diff --git a/modules/installer/tools/installer2/nixos-bootstrap.sh b/modules/installer/tools/installer2/nixos-bootstrap.sh deleted file mode 100644 index 9c972bd6d95..00000000000 --- a/modules/installer/tools/installer2/nixos-bootstrap.sh +++ /dev/null @@ -1,137 +0,0 @@ -#! @shell@ -# runs in chroot -# creates mandatory directories such as /var -# finally runs switch-to-configuration optionally registering grub -set -e - -usage(){ - cat << EOF - script --install [--fast] [--no-grub] - - --no-pull: don't do a nix-pull to get the latest Nixpkgs - channel manifest - - --no-grub: don't install grub ( you don't want this ..) - - --debug: set -x - - options which will be passed to nix-env: - - -j n : number of build tasks done simultaniously - --keep-going: Build as much as possible. - - Description: - This scripts installs NixOS and should be run within the target chroot. - - The minimal nix system must have been installed previously. - Eg nixos-prepare-install.sh does this for you. - - Probably this script is distributed along with the minimal nix closure used - for bootstrapping -EOF - exit 1 -} - -die(){ echo "!>> " $@; exit 1; } - -check(){ - [ -e "$1" ] || die "$1 not found $2" -} -WARN(){ echo "WARNING: $@"; } -INFO(){ echo "INFO: " $@; } - -# == configuration == - -HOME=${HOME:-/root} -NIXOS=${NIXOS:-/etc/nixos/nixos} -NIXPKGS=${NIXPKGS:-/etc/nixos/nixpkgs} -NIXOS_CONFIG=${NIXOS_CONFIG:-/etc/nixos/configuration.nix} -NIXOS_PULL=${NIXOS_PULL:-1} -NIXOS_INSTALL_GRUB=${NIXOS_INSTALL_GRUB:-1} - -ps="run-in-chroot" - -check "$NIXOS_CONFIG" -check "$NIXOS/modules" "nixos repo not found" -check "$NIXPKGS/pkgs/top-level/all-packages.nix" "nixpgks repo not found" -for d in /dev /sys /proc; do - check "$d" "It should have been mounted by $ps" -done - -# try reusing binaries from host system (which is most likely an installation CD) -if [ -d /host-system/nix ]; then - export NIX_OTHER_STORES=/host-system/nix${NIX_OTHER_STORES:+:}$NIX_OTHER_STORES -else - WARN "/host-system/nix not found. It should have been --bind mounted by $ps. - I won't be able to take binaries from the installation media. - " -fi - -# == configuration end == - -INSTALL= - -for arg in $@; do - case $arg in - --no-pull) NIXOS_PULL=0;; - --install) INSTALL=1;; - --no-grub) NIXOS_INSTALL_GRUB=;; - --debug) set -x;; - -j*) NIX_ENV_ARGS="$NIX_ENV_ARGS $arg";; - --keep-going) NIX_ENV_ARGS="$NIX_ENV_ARGS $arg";; - *) usage; - esac -done - -if [ "$INSTALL" != 1 ]; then - usage -fi - - -# We don't have locale-archive in the chroot, so clear $LANG. -export LANG= - -export PATH=@coreutils@/bin - -mkdir -m 01777 -p /tmp -mkdir -m 0755 -p /var - -# Create the necessary Nix directories on the target device, if they -# don't already exist. -mkdir -m 0755 -p \ - /nix/var/nix/gcroots \ - /nix/var/nix/temproots \ - /nix/var/nix/manifests \ - /nix/var/nix/userpool \ - /nix/var/nix/profiles \ - /nix/var/nix/db \ - /nix/var/log/nix/drvs - -# Do a nix-pull to speed up building. -if test -n "@nixpkgsURL@" -a ${NIXOS_PULL} != 0; then - @nix@/bin/nix-pull @nixpkgsURL@/MANIFEST || true -fi - -# Build the specified Nix expression in the target store and install -# it into the system configuration profile. -INFO "building the system configuration..." -@nix@/bin/nix-env \ - -p /nix/var/nix/profiles/system \ - -f "$NIXOS" \ - --set -A system \ - $NIX_ENV_ARGS - -# Mark the target as a NixOS installation, otherwise -# switch-to-configuration will chicken out. -touch /etc/NIXOS - -# Grub needs an mtab. -ln -sfn /proc/mounts /etc/mtab - - -# Switch to the new system configuration. This will install Grub with -# a menu default pointing at the kernel/initrd/etc of the new -# configuration. -INFO "finalising the installation..." -export NIXOS_INSTALL_GRUB -/nix/var/nix/profiles/system/bin/switch-to-configuration boot diff --git a/modules/installer/tools/installer2/nixos-prepare-install.sh b/modules/installer/tools/installer2/nixos-prepare-install.sh deleted file mode 100644 index 548581f0c21..00000000000 --- a/modules/installer/tools/installer2/nixos-prepare-install.sh +++ /dev/null @@ -1,239 +0,0 @@ -#!/bin/sh - -# prepare installation by putting in place unless present: -# /etc/nixos/nixpkgs -# /etc/nixos/nixos -# /etc/nixos/configuration.nix - - -set -e - -usage(){ - cat << EOF - script options [list of actions] - - actions: - - guess-config: run nixos-hardware-scan > T/configuration.nix - copy-nix: copy minimal nix system which can bootstrap the whole system - This creates the $mountPoint/bin/sh symlink - If you're bootstrapping from an archive store paths are registered valid only - copy-nixos-bootstrap: - copy the nixos-bootstrap script to /nix/store where it will be - garbage collected later - copy-sources: copy repos into T/ - checkout-sources: svn checkout official repos into T/ - - - where T=$T - and repos = $ALL_REPOS - - options: - --force: If targets exist no action will taken unless you use --force - in which case target is renamed before action is run - --dir-ok: allow installing into directory (omits is mount point check) - - --debug: set -x - - - default list of actions: $DEFAULTS -EOF - exit 1 -} - - -INFO(){ echo "INFO: " $@; } - -# = configuration = - -FORCE_ACTIONS=${FORCE_ACTIONS:-} -ALL_REPOS="nixpkgs nixos" -mountPoint=${mountPoint:-/mnt} - -if [ -e $mountPoint/README-BOOTSTRAP-NIXOS ]; then - INFO "$mountPoint/README-BOOTSTRAP-NIXOS found, assuming your're bootstrapping from an archive. Nix files should be in place" - FROM_ARCHIVE=1 - DEFAULTS="guess-config copy-nix" -else - FROM_ARCHIVE=0 - DEFAULTS="guess-config copy-nixos-bootstrap copy-nix copy-sources" -fi - -backupTimestamp=$(date "+%Y%m%d%H%M%S") -SRC_BASE=${SRC_BASE:-"/etc/nixos"} -SVN_BASE="https://svn.nixos.org/repos/nix" -MUST_BE_MOUNTPOINT=${MUST_BE_MOUNTPOINT:-1} -T="$mountPoint/etc/nixos" - -NIX_CLOSURE=${NIX_CLOSURE:-@nixClosure@} - -die(){ echo "!>> " $@; exit 1; } - -## = read options = -# actions is used by main loop at the end -ACTIONS="" -# check and handle options: -for a in $@; do - case "$a" in - copy-nix|copy-nixos-bootstrap|guess-config|copy-sources|checkout-sources) - ACTIONS="$ACTIONS $a" - ;; - --dir-ok) - MUST_BE_MOUNTPOINT=false - ;; - --force) - FORCE_ACTIONS=1 - ;; - --debug) - set -x - ;; - *) - echo "unkown option: $a" - usage - ;; - esac -done -[ -n "$ACTIONS" ] || ACTIONS="$DEFAULTS" - - -if ! grep -F -q " $mountPoint " /proc/mounts && [ "$MUST_BE_MOUNTPOINT" = 1 ]; then - die "$mountPoint doesn't appear to be a mount point" -fi - -# = utils = - -backup(){ - local dst="$(dirname "$1")/$(basename "$1")-$backupTimestamp" - INFO "backing up: $1 -> $dst" - mv "$1" "$dst" -} - -# = implementation = - -# exit status = 0: target exists -# exti status != 0: target must be rebuild either because --force was given or -# because it didn't exist yet -target_realised(){ - if [ -e "$1" ] && [ "$FORCE_ACTIONS" = 1 ]; then - backup "$1" - fi - - [ -e "$1" ] && { - INFO "not realsing $1. Target already exists. Use --force to force." - } -} - -createDirs(){ - mkdir -m 0755 -p $mountPoint/etc/nixos - mkdir -m 1777 -p $mountPoint/nix/store -} - - -realise_repo(){ - local action=$1 - local repo=$2 - - createDirs - - if [ "$action" == "copy-sources" ]; then - - local repo_sources="${repo}_SOURCES" - rsync -a -r "${SRC_BASE}/$repo" "$T" - - else - - INFO "checking out $repo" - svn co "$SVN_BASE/$repo/trunk" "$T/$repo" - - fi - -} - -# only keep /nix/store/* lines -# print them only once -pathsFromGraph(){ - declare -A a - local prefix=/nix/store/ - while read l; do - if [ "${l/#$prefix/}" != "$l" ] && [ -z "${a["$l"]}" ]; then - echo "$l"; - a["$l"]=1; - fi - done -} - -# = run actions: = -for a in $ACTIONS; do - case "$a" in - - guess_config) - local config="$T/configuration.nix" - target_realised "$config" || { - INFO "creating simple configuration file" - nixos-hardware-scan > "$config" - echo - INFO "Note: you can start customizing $config while remaining actions will are being executed" - echo - } - ;; - - copy-nixos-bootstrap) - createDirs - # this script will be garbage collected somewhen: - cp @nixosBootstrap@/bin/nixos-bootstrap $mountPoint/nix/store/ - ;; - - copy-nix) - if [ "$FROM_ARCHIVE" = 1 ]; then - NIX_CLOSURE=${mountPoint}@nixClosure@ - else - INFO "Copy Nix to the Nix store on the target device." - createDirs - echo "copying Nix to $mountPoint...." - - for i in `cat $NIX_CLOSURE | pathsFromGraph`; do - echo " $i" - rsync -a $i $mountPoint/nix/store/ - done - - fi - - [ -e "$NIX_CLOSURE" ] || die "Couldn't find nixClosure $NIX_CLOSURE anywhere. Can't register inital store paths valid. Exiting" - - # Create the required /bin/sh symlink; otherwise lots of things - # (notably the system() function) won't work. - mkdir -m 0755 -p $mountPoint/bin - ln -sf @shell@ $mountPoint/bin/sh - - INFO "registering bootstrapping store paths as valid so that they won't be rebuild" - # Register the paths in the Nix closure as valid. This is necessary - # to prevent them from being deleted the first time we install - # something. (I.e., Nix will see that, e.g., the glibc path is not - # valid, delete it to get it out of the way, but as a result nothing - # will work anymore.) - # TODO: check permissions so that paths can't be changed later? - chroot "$mountPoint" @nix@/bin/nix-store --register-validity < $NIX_CLOSURE - - ;; - - copy-sources|checkout-sources) - - for repo in $ALL_REPOS; do - target_realised "$T/$repo" || realise_repo $a $repo - done - - ;; - esac -done - -if [ -e "$T/nixos" ] && [ -e "$T/nixpkgs" ] && [ -e "$T/configuration.nix" ]; then - cat << EOF - To realise your NixOS installtion execute: - - run-in-chroot "/nix/store/nixos-bootstrap --install -j2 --keep-going" -EOF -else - for t in "$T/configuration.nix" "$T/nixpkgs" "$T/configuration.nix"; do - INFO "you can't start because $t is missing" - done -fi diff --git a/modules/installer/tools/installer2/run-in-chroot.sh b/modules/installer/tools/installer2/run-in-chroot.sh deleted file mode 100644 index f4cc4cb9523..00000000000 --- a/modules/installer/tools/installer2/run-in-chroot.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -# helper script preparing chroot by mounting /dev /proc /sys etc - -set -e - -usage(){ - cat << EOF - $SCRIPT OPTS or cmd - OPTS: - --prepare : only mount - --unprepare : only unmount - --debug : set -x - - $SCRIPT --prepare: prepare chroot only - $SCRIPT --unprepare: unprepare chroot only - $SCRIPT command: run /bin/sh command in chroot - - usage example run a shell in chroot: - $SCRIPT path-to-sh - -EOF - exit 1 -} - -die(){ echo "!>> " $@; exit 1; } -INFO(){ echo "INFO: " $@; } - -prepare(){ - INFO "Enable networking: copying /etc/resolv.conf" - mkdir -m 0755 -p $mountPoint/etc - touch /etc/resolv.conf - cp /etc/resolv.conf $mountPoint/etc/ - - INFO "mounting /proc /sys /dev and / to /host-system" - mkdir -m 0755 -p $mountPoint/{dev,proc,sys,host-system} - mount --bind /dev $mountPoint/dev - mount --bind /proc $mountPoint/proc - mount --bind /sys $mountPoint/sys - mount --rbind / $mountPoint/host-system -} - -unprepare(){ - INFO "unmounting /proc /sys /dev and removing /host-system if empty" - for d in $mountPoint/{host-system,dev,proc,sys}; do - umount -l "$d" - done - # no -fr !! - rmdir $mountPoint/host-system -} - -run_cmd(){ - prepare - trap "unprepare" EXIT - chroot $mountPoint $@ -} - - -SCRIPT="$(basename "$0")" -mountPoint=${mountPoint:-/mnt} - -[ -d $mountPoint ] || die "$mountPoint is not a directory" - -while [ "$#" > 0 ]; do - case $1 in - - --debug) shift; set -x;; - - -h|--help) shift; usage;; - - --prepare) shift; prepare;; - - --unprepare) shift; unprepare;; - - *) - run_cmd "$@" - exit 0 - ;; - esac -done diff --git a/modules/installer/tools/nixos-bootstrap-archive/README-BOOTSTRAP-NIXOS b/modules/installer/tools/nixos-bootstrap-archive/README-BOOTSTRAP-NIXOS deleted file mode 100644 index b70dc010cc3..00000000000 --- a/modules/installer/tools/nixos-bootstrap-archive/README-BOOTSTRAP-NIXOS +++ /dev/null @@ -1,12 +0,0 @@ -HOWTO install NixOS from a bootstrap archive -============================================= - -export mountPoint=$target # defaults to /mnt -tar xfj $ARCHIV -C $mountPoint - -bash $mountPoint/nix/store/nixos-prepare-install # see --help - -$EDITOR $mountPoint/etc/nixos/configuration.nix - -# you can replace --install by --help to get more info -bash $mountPoint/nix/store/run-in-chroot "/nix/store/nixos-bootstrap --install" diff --git a/modules/installer/tools/nixos-bootstrap-archive/default.nix b/modules/installer/tools/nixos-bootstrap-archive/default.nix deleted file mode 100644 index 3fa287bf898..00000000000 --- a/modules/installer/tools/nixos-bootstrap-archive/default.nix +++ /dev/null @@ -1,22 +0,0 @@ -args: with args; - -# TODO add revision number or such -runCommand "nixos-bootstrap-archive" { } '' - PATH=${perl}/bin:${coreutils}/bin:${gnutar}/bin:${bzip2}/bin - storePaths=$(perl ${pathsFromGraph} ${nixClosure}) - - s(){ echo -C $(dirname $1) $(basename $1); } - - mkdir $out - tar cf tmp.tar ${nixClosure} $storePaths - cp ${./README-BOOTSTRAP-NIXOS} README-BOOTSTRAP-NIXOS - tar --append -f tmp.tar README-BOOTSTRAP-NIXOS - tar --append -f tmp.tar --transform 's@^@/nix/store/@' \ - $(s ${nixosPrepareInstall}/bin/nixos-prepare-install ) \ - $(s ${runInChroot}/bin/run-in-chroot ) \ - $(s ${nixosBootstrap}/bin/nixos-bootstrap ) - - cat tmp.tar | bzip2 > $out/nixos-install-archive.tar.bz2 - ensureDir $out/nix-support - echo "file tarball" $out/nixos-install-archive.tar.bz2 > $out/nix-support/hydra-build-products -'' diff --git a/modules/installer/tools/tools.nix b/modules/installer/tools/tools.nix index cf2bdb788cf..069e45127ef 100644 --- a/modules/installer/tools/tools.nix +++ b/modules/installer/tools/tools.nix @@ -35,48 +35,6 @@ let "cp refs $out"; }; - # rewrite of nixosInstall: each tool does exactly one job. - # So they get more useful. - installer2 = - let nixClosure = pkgs.runCommand "closure" - {exportReferencesGraph = ["refs" config.environment.nix];} - "cp refs $out"; - - nix = config.environment.nix; - in rec { - - nixosPrepareInstall = makeProg { - name = "nixos-prepare-install"; - src = ./installer2/nixos-prepare-install.sh; - - inherit nix nixClosure nixosBootstrap; - }; - - runInChroot = makeProg { - name = "run-in-chroot"; - src = ./installer2/run-in-chroot.sh; - }; - - nixosBootstrap = makeProg { - name = "nixos-bootstrap"; - src = ./installer2/nixos-bootstrap.sh; - - inherit (pkgs) coreutils; - inherit nixClosure nix; - - # TODO shell ? - nixpkgsURL = cfg.nixpkgsURL; - }; - - # see ./nixos-bootstrap-archive/README-BOOTSTRAP-NIXOS - # TODO refactor: It should *not* depend on configuration.nix - # maybe even move this in nixpkgs? - minimalInstallArchive = import ./nixos-bootstrap-archive { - inherit (pkgs) stdenv runCommand perl pathsFromGraph gnutar coreutils bzip2; - inherit nixosPrepareInstall runInChroot nixosBootstrap nixClosure; - }; - }; - nixosRebuild = makeProg { name = "nixos-rebuild"; src = ./nixos-rebuild.sh; @@ -170,19 +128,13 @@ in nixosDeployNetwork nixosInstall nixosRebuild - nixosHardwareScan - nixosGenSeccureKeys - nixosOption - - installer2.runInChroot - installer2.nixosPrepareInstall + nixosHardwareScan + nixosGenSeccureKeys + nixosOption ] ++ pkgs.lib.optional cfg.enableGraphicalTools nixosGui; system.build = { inherit nixosInstall nixosHardwareScan nixosOption; - - # expose scripts - inherit (installer2) nixosPrepareInstall runInChroot nixosBootstrap minimalInstallArchive; }; }; }