From 26963cfc2dfd8ba6bce927535317d799dda15102 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 22 Oct 2015 19:40:00 +0200 Subject: switch-to-configuration: Fix unit name quoting. Clearly it would be the best if we'd directly generate mount units instead of converting /etc/fstab. But in order to do that we need to test it throughly so this approach is for the next stable release. This fix however is intended for inclusion into release-14.12 and release-15.09. Using a simple regular expression unfortunately isn't sufficient for proper mount unit name quoting/escaping and there is a utility in systemd called systemd-escape which does nothing less than that. Of course, using an external program to escape the unit name is way more expensive and causes us to fork for each mount point. But given that we already do quite a lot of forks just for unit starting and stopping, I think it doesn't matter that much. Well, except if you have a whole bunch of mount points. However, if the latter is the case and you have thousands of mount points, you probably have stumbled over this already if your mount point contains a dash. As for my motivation to fix this: I've stumbled on this while trying to fix the "none" backend test for NixOps (see NixOS/nixops#350), where the target machines use /nix/.ro-store and /nix/.rw-store as mount points. The implementation we had so far did improperly escape it so those mount points got the following unit files: * nix-.ro-store.mount * nix-.rw-store.mount The correct names for these units are however: * nix-.ro\x2dstore.mount * nix-.rw\x2dstore.mount So using systemd-escape now properly generates these names. Signed-off-by: aszlig --- nixos/modules/system/activation/switch-to-configuration.pl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'nixos/modules/system/activation') diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 655fbab2a843..747de89905dc 100644 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -261,12 +261,12 @@ while (my ($unit, $state) = each %{$activePrev}) { sub pathToUnitName { my ($path) = @_; - die unless substr($path, 0, 1) eq "/"; - return "-" if $path eq "/"; - $path = substr($path, 1); - $path =~ s/\//-/g; - # FIXME: handle - and unprintable characters. - return $path; + open my $cmd, "-|", "systemd-escape", "--suffix=mount", "-p", $path + or die "Unable to escape $path!\n"; + my $escaped = join "", <$cmd>; + chomp $escaped; + close $cmd or die; + return $escaped; } sub unique { @@ -290,7 +290,7 @@ my ($newFss, $newSwaps) = parseFstab "$out/etc/fstab"; foreach my $mountPoint (keys %$prevFss) { my $prev = $prevFss->{$mountPoint}; my $new = $newFss->{$mountPoint}; - my $unit = pathToUnitName($mountPoint) . ".mount"; + my $unit = pathToUnitName($mountPoint); if (!defined $new) { # Filesystem entry disappeared, so unmount it. $unitsToStop{$unit} = 1; -- cgit 1.4.1 From 392ca77d4c0c5e05ad23378de370ea964c29848f Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Sat, 4 Jul 2015 18:53:26 +1200 Subject: nixos/activation-script: fix formatting of example --- .../system/activation/activation-script.nix | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'nixos/modules/system/activation') diff --git a/nixos/modules/system/activation/activation-script.nix b/nixos/modules/system/activation/activation-script.nix index d78ec0d7bf3d..854fa2f40b69 100644 --- a/nixos/modules/system/activation/activation-script.nix +++ b/nixos/modules/system/activation/activation-script.nix @@ -30,18 +30,19 @@ in system.activationScripts = mkOption { default = {}; - example = { - stdio = { - text = '' - # Needed by some programs. - ln -sfn /proc/self/fd /dev/fd - ln -sfn /proc/self/fd/0 /dev/stdin - ln -sfn /proc/self/fd/1 /dev/stdout - ln -sfn /proc/self/fd/2 /dev/stderr - ''; - deps = []; - }; - }; + example = literalExample '' + { stdio = { + text = ''' + # Needed by some programs. + ln -sfn /proc/self/fd /dev/fd + ln -sfn /proc/self/fd/0 /dev/stdin + ln -sfn /proc/self/fd/1 /dev/stdout + ln -sfn /proc/self/fd/2 /dev/stderr + '''; + deps = []; + }; + } + ''; description = '' A set of shell script fragments that are executed when a NixOS -- cgit 1.4.1 From f8516a0717569f496653821d5fa286da59854550 Mon Sep 17 00:00:00 2001 From: Vladimír Čunát Date: Sun, 28 Feb 2016 10:06:27 +0100 Subject: nixos copySystemConfiguration: fix when chrooted Fixes #7974. Also makes the description more informative. --- nixos/modules/system/activation/top-level.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'nixos/modules/system/activation') diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix index d66580b7b9be..2d1b0ffb54ce 100644 --- a/nixos/modules/system/activation/top-level.nix +++ b/nixos/modules/system/activation/top-level.nix @@ -178,9 +178,10 @@ in default = false; description = '' If enabled, copies the NixOS configuration file - $NIXOS_CONFIG (usually - /etc/nixos/configuration.nix) - to the system store path. + (usually /etc/nixos/configuration.nix) + and links it from the resulting system + (getting to /run/current-system/configuration.nix). + Note that only this single file is copied, even if it imports others. ''; }; @@ -238,7 +239,9 @@ in system.extraSystemBuilderCmds = optionalString config.system.copySystemConfiguration - "cp ${maybeEnv "NIXOS_CONFIG" "/etc/nixos/configuration.nix"} $out"; + ''ln -s '${import ../../../lib/from-env.nix "NIXOS_CONFIG" }' \ + "$out/configuration.nix" + ''; system.build.toplevel = system; -- cgit 1.4.1