diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-05-28 13:17:56 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-05-28 13:17:56 +0000 |
commit | 3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7 (patch) | |
tree | 4ed77f7bab5772a0b423f87d855d02bce869b17f /modules | |
parent | 14f1c81822d3eb855ea47abf9d53bc4b06659385 (diff) | |
download | nixpkgs-3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7.tar nixpkgs-3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7.tar.gz nixpkgs-3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7.tar.bz2 nixpkgs-3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7.tar.lz nixpkgs-3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7.tar.xz nixpkgs-3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7.tar.zst nixpkgs-3c84d56273ff6a5eb07d83448a3b046cb6c5ebc7.zip |
* Move the /etc generation to modules/system/etc.
svn path=/nixos/branches/modular-nixos/; revision=15767
Diffstat (limited to 'modules')
-rw-r--r-- | modules/legacy.nix | 1 | ||||
-rw-r--r-- | modules/module-list.nix | 1 | ||||
-rw-r--r-- | modules/programs/bash/bash.nix | 19 | ||||
-rw-r--r-- | modules/system/etc/etc.nix | 91 | ||||
-rw-r--r-- | modules/system/etc/make-etc.nix | 12 | ||||
-rw-r--r-- | modules/system/etc/make-etc.sh | 22 |
6 files changed, 145 insertions, 1 deletions
diff --git a/modules/legacy.nix b/modules/legacy.nix index 67a99ea900c..8b4d7199ae0 100644 --- a/modules/legacy.nix +++ b/modules/legacy.nix @@ -1,6 +1,5 @@ { require = [ - ../etc/default.nix ../system/assertion.nix ../system/nixos-environment.nix ../system/nixos-installer.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index a6843e09702..b10905fc35e 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -117,6 +117,7 @@ ./system/boot/kernel.nix ./system/boot/stage-1.nix ./system/boot/stage-2.nix + ./system/etc/etc.nix ./system/upstart-events/ctrl-alt-delete.nix ./system/upstart-events/halt.nix ./system/upstart-events/maintenance-shell.nix diff --git a/modules/programs/bash/bash.nix b/modules/programs/bash/bash.nix index d992d0888ba..205cadea7f3 100644 --- a/modules/programs/bash/bash.nix +++ b/modules/programs/bash/bash.nix @@ -3,7 +3,26 @@ {config, pkgs, ...}: +let + + options = { + + environment.shellInit = pkgs.lib.mkOption { + default = ""; + example = ''export PATH=/godi/bin/:$PATH''; + description = " + Script used to initialized user shell environments. + "; + merge = pkgs.lib.mergeStringOption; + }; + + }; + +in + { + require = [options]; + environment.etc = [ { # /etc/bashrc: script executed when the shell starts as a # non-login shell. /etc/profile also sources this file, so diff --git a/modules/system/etc/etc.nix b/modules/system/etc/etc.nix new file mode 100644 index 00000000000..c499cc0583a --- /dev/null +++ b/modules/system/etc/etc.nix @@ -0,0 +1,91 @@ +# produce a script to generate /etc +{config, pkgs, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption; + + option = { + environment.etc = mkOption { + default = []; + example = [ + { source = "/nix/store/.../etc/dir/file.conf.example"; + target = "dir/file.conf"; + mode = "0440"; + } + ]; + description = '' + List of files that have to be linked in /etc. + ''; + }; + }; +in + +###### implementation +let + + copyScript = {source, target, mode ? "644", own ? "root.root"}: + assert target != "nixos"; + '' + source="${source}" + target="/etc/${target}" + mkdir -p $(dirname "$target") + test -e "$target" && rm -f "$target" + cp "$source" "$target" + chown ${own} "$target" + chmod ${mode} "$target" + ''; + + makeEtc = import ./make-etc.nix { + inherit (pkgs) stdenv; + configFiles = config.environment.etc; + }; + +in + +{ + require = [option]; + + system = { + build = { + etc = makeEtc; + }; + + activationScripts = { + etc = pkgs.lib.fullDepEntry '' + # Set up the statically computed bits of /etc. + staticEtc=/etc/static + rm -f $staticEtc + ln -s ${makeEtc}/etc $staticEtc + for i in $(cd $staticEtc && find * -type l); do + mkdir -p /etc/$(dirname $i) + rm -f /etc/$i + if test -e "$staticEtc/$i.mode"; then + # Create a regular file in /etc. + cp $staticEtc/$i /etc/$i + chown 0.0 /etc/$i + chmod "$(cat "$staticEtc/$i.mode")" /etc/$i + else + # Create a symlink in /etc. + ln -s $staticEtc/$i /etc/$i + fi + done + + # Remove dangling symlinks that point to /etc/static. These are + # configuration files that existed in a previous configuration but not + # in the current one. For efficiency, don't look under /etc/nixos + # (where all the NixOS sources live). + for i in $(find /etc/ \( -path /etc/nixos -prune \) -o -type l); do + target=$(readlink "$i") + if test "''${target:0:''${#staticEtc}}" = "$staticEtc" -a ! -e "$i"; then + rm -f "$i" + fi + done + '' [ + "systemConfig" + "defaultPath" # path to cp, chmod, chown + "stdio" + ]; + }; + }; +} diff --git a/modules/system/etc/make-etc.nix b/modules/system/etc/make-etc.nix new file mode 100644 index 00000000000..94ea248f669 --- /dev/null +++ b/modules/system/etc/make-etc.nix @@ -0,0 +1,12 @@ +{stdenv, configFiles}: + +stdenv.mkDerivation { + name = "etc"; + + builder = ./make-etc.sh; + + /* !!! Use toXML. */ + sources = map (x: x.source) configFiles; + targets = map (x: x.target) configFiles; + modes = map (x: if x ? mode then x.mode else "symlink") configFiles; +} diff --git a/modules/system/etc/make-etc.sh b/modules/system/etc/make-etc.sh new file mode 100644 index 00000000000..4b7bb68be4b --- /dev/null +++ b/modules/system/etc/make-etc.sh @@ -0,0 +1,22 @@ +source $stdenv/setup + +ensureDir $out/etc + +sources_=($sources) +targets_=($targets) +modes_=($modes) +for ((i = 0; i < ${#targets_[@]}; i++)); do + ensureDir $out/etc/$(dirname ${targets_[$i]}) + if ! test -e $out/etc/${targets_[$i]}; then + ln -s ${sources_[$i]} $out/etc/${targets_[$i]}; + else + echo Duplicate entry "${targets_[$i]} -> ${sources_[$i]}" + if test "$(readlink "$targets_[$i]")" -ne "$sources_[$i]"; then + echo Mismatched duplicate entry "$(readlink "$targets_[$i]") "'<>'" $sources_[$i]" + exit 1 + fi + fi; + if test "${modes_[$i]}" != symlink; then + echo "${modes_[$i]}" > $out/etc/${targets_[$i]}.mode + fi +done |