From e7e45dbd2c8c650c5a3a442b452a8b578c6b847f Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Fri, 2 Jan 2009 16:06:46 +0000 Subject: [PATCH] Start moving the "activate configuration" script to be extensible. svn path=/nixos/branches/fix-style/; revision=13675 --- system/activate-configuration.nix | 43 +++++++++++++++++++++++++++ system/activate-configuration.sh | 16 +---------- system/options.nix | 2 ++ system/system-options.nix | 48 +++++++++++++++++++++++++++++++ system/system.nix | 9 ++---- 5 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 system/activate-configuration.nix create mode 100644 system/system-options.nix diff --git a/system/activate-configuration.nix b/system/activate-configuration.nix new file mode 100644 index 000000000000..65591c2d2b84 --- /dev/null +++ b/system/activate-configuration.nix @@ -0,0 +1,43 @@ +# generate the script used to activate the configuration. +{pkgs, config, ...}: + +let + inherit (pkgs.stringsWithDeps) textClosureOverridable; + inherit (pkgs.lib) mkOption mergeTypedOption mergeAttrs mapRecordFlatten id; + + textClosure = steps: + textClosureOverridable steps + (["#!/bin/sh"] ++ (mapRecordFlatten (a: v: v) steps)); + + aggregateScripts = name: steps: + pkgs.writeScript name (textClosure steps); +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 = []; + }; + }; + description = '' + Activate the new configuration (i.e., update /etc, make accounts, + and so on). + ''; + merge = mergeTypedOption "script" builtins.isAttrs mergeAttrs; + apply = lib: { + inherit lib; # used to fetch dependencies. + script = aggregateScripts "activationScript" lib; + }; + }; + }; +} diff --git a/system/activate-configuration.sh b/system/activate-configuration.sh index fb4c6a91da65..ea329ce23652 100644 --- a/system/activate-configuration.sh +++ b/system/activate-configuration.sh @@ -1,20 +1,6 @@ #! @shell@ -systemConfig="$1" -if test -z "$systemConfig"; then - systemConfig="/system" # for the installation CD -fi - -export PATH=/empty -for i in @path@; do PATH=$PATH:$i/bin:$i/sbin; done - - -# 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 - +source @newActivationScript@ # Set up the statically computed bits of /etc. staticEtc=/etc/static diff --git a/system/options.nix b/system/options.nix index 2285f6f89aed..ce7667b2fa8a 100644 --- a/system/options.nix +++ b/system/options.nix @@ -2912,6 +2912,8 @@ root ALL=(ALL) SETENV: ALL require = [ # system + (import ../system/system-options.nix) + (import ../system/activate-configuration.nix) (import ../upstart-jobs/default.nix) # newtworking diff --git a/system/system-options.nix b/system/system-options.nix new file mode 100644 index 000000000000..1924db9aec89 --- /dev/null +++ b/system/system-options.nix @@ -0,0 +1,48 @@ +# this file contains all extendable options originally defined in system.nix +{pkgs, config, ...}: + +let + inherit (pkgs.stringsWithDeps) noDepEntry FullDepEntry PackEntry; + + activateLib = config.system.activationScripts.lib; +in + +{ + require = [ + # config.system.activationScripts + (import ../system/activate-configuration.nix) + ]; + + system = { + activationScripts = { + systemConfig = noDepEntry '' + systemConfig="$1" + if test -z "$systemConfig"; then + systemConfig="/system" # for the installation CD + fi + ''; + + defaultPath = + let path = [ + pkgs.coreutils pkgs.gnugrep pkgs.findutils + pkgs.glibc # needed for getent + pkgs.pwdutils + ]; in noDepEntry '' + export PATH=/empty + for i in ${toString path}; do + PATH=$PATH:$i/bin:$i/sbin; + done + ''; + + stdio = FullDepEntry '' + # 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 + '' [ + activateLib.defaultPath # path to ln + ]; + }; + }; +} diff --git a/system/system.nix b/system/system.nix index 659b647829d1..5f05a4ddde88 100644 --- a/system/system.nix +++ b/system/system.nix @@ -196,10 +196,13 @@ rec { # The script that activates the configuration, i.e., it sets up # /etc, accounts, etc. It doesn't do anything that can only be done # at boot time (such as start `init'). + # DO NOT EXTEND THIS. You should use the option system-option.nix activateConfiguration = pkgs.substituteAll rec { src = ./activate-configuration.sh; isExecutable = true; + newActivationScript = config.system.activationScripts.script; + inherit etc wrapperDir systemPath modprobe defaultShell kernel; hostName = config.networking.hostName; setuidPrograms = @@ -212,12 +215,6 @@ rec { inherit (usersGroups) createUsersGroups usersList groupsList; - path = [ - pkgs.coreutils pkgs.gnugrep pkgs.findutils - pkgs.glibc # needed for getent - pkgs.pwdutils - ]; - bash = pkgs.bashInteractive; adjustSetuidOwner = pkgs.lib.concatStrings (map