diff options
author | tv <tv@krebsco.de> | 2017-12-05 22:12:57 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2017-12-05 22:12:57 +0100 |
commit | 3ae89eddab58078f8d06cdda330c24f74a439096 (patch) | |
tree | 7a2451131e1d86306a593f2be6dcecfe5e3e0143 /shell.nix | |
parent | 8030352c450432a0cee14f561241831875f8399b (diff) |
shell deploy: add --diff
Diffstat (limited to 'shell.nix')
-rw-r--r-- | shell.nix | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -7,6 +7,7 @@ let # cmds.deploy = pkgs.withGetopt { + diff = { default = /* sh */ "false"; switch = true; }; force-populate = { default = /* sh */ "false"; switch = true; }; quiet = { default = /* sh */ "false"; switch = true; }; source_file = { @@ -22,6 +23,65 @@ let . ${init.env} . ${init.proxy "deploy" opts} + if \test ${opts.diff.ref} = true; then + + system_profile=/nix/var/nix/profiles/system + system_drv_cur=/etc/system.drv + + system_drv_new=$( + ${pkgs.nix}/bin/nix-instantiate \ + -Q \ + -I "$target_path" \ + -E ' + (import <nixpkgs/nixos/lib/eval-config.nix> { + modules = [ <nixos-config> ]; + }).config.system.build.toplevel + ' + ) + + if \test -e "$system_drv_cur"; then + + system_drv_cur_c=$(${pkgs.coreutils}/bin/readlink -f "$system_drv_cur") + system_drv_new_c=$(${pkgs.coreutils}/bin/readlink -f "$system_drv_new") + + if \test "$system_drv_cur_c" = "$system_drv_new_c"; then + echo "$0: system up to date" >&2 + exit 0 + fi + + system_drv_cur=$system_drv_cur_c \ + system_drv_new=$system_drv_new_c \ + ${pkgs.utillinux}/bin/script \ + --command ' + ${pkgs.haskellPackages.nix-diff}/bin/nix-diff \ + "$system_drv_cur" "$system_drv_new" + ' \ + --quiet \ + --return \ + /dev/null + + printf 'deploy? [N/y] ' >&2 + read -r REPLY + if \test "$REPLY" != y; then + echo "$0: abort!" >&2 + exit 1 + fi + else + echo "$0: --${opts.diff.long} has no effect because "$system_drv_cur" doesn't exist" >&2 + fi + + new_system=$(${pkgs.nix}/bin/nix-store --realize "$system_drv_new") + + ${pkgs.nix}/bin/nix-env -p "$system_profile" --set "$new_system" + PATH=${lib.makeBinPath [ + pkgs.systemd + ]} \ + "$system_profile"/bin/switch-to-configuration switch + + ${pkgs.coreutils}/bin/ln -fns "$system_drv_new" "$system_drv_cur" + exit + fi + # Use system's nixos-rebuild, which is not self-contained export PATH=/run/current-system/sw/bin exec ${utils.with-whatsupnix} \ |