about summary refs log tree commit diff
path: root/pkgs/profpatsch/deploy.nix
blob: 2e9f1493290e87a51d712935535b4a1e91d54fc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# The only deployment tool that anybody should take seriously
{ pkgs, getBins }:

let
  bins = getBins pkgs.coreutils [ "realpath" ]
      // getBins pkgs.openssh [ "ssh" ]
      // getBins pkgs.nix [ "nix-build" "nix-copy-closure" "nix-env" ]
      ;

  deploy = pkgs.writers.writeDash "deploy-machine-profpatsch" ''
    set -e
    MACHINE="''${1?please set machine as first argument}"
    HOME="''${HOME?please make sure HOME is set}"
    VUIZVUI="$HOME/vuizvui"
    OUT_LINK="$VUIZVUI/machines/profpatsch/system-$MACHINE"

    cmd() {
      echo "$" "$@" 1>&2
      "$@"
    }

    cmd ${bins.nix-build} \
      --show-trace \
      --out-link "$OUT_LINK" \
      -I "nixpkgs=$HOME/nixpkgs" \
      -A "machines.profpatsch.$MACHINE.build" \
      "$VUIZVUI"

    # copy all required paths to the machine
    cmd ${bins.nix-copy-closure} \
      --to "$MACHINE?compress=true" \
      --use-substitutes \
      ${create-system-profile-and-switch} \
      "$OUT_LINK"

    # activate the system
    cmd ${bins.ssh} \
      "root@$MACHINE" \
      ${create-system-profile-and-switch} \
      "$(${bins.realpath} $OUT_LINK)"
  '';

  create-system-profile-and-switch = pkgs.writers.writeDash "create-system-profile-and-switch" ''
    set -e
    system="$1"
    ${bins.nix-env} -p /nix/var/nix/profiles/system --set $system
    $system/bin/switch-to-configuration switch
  '';

in {
  inherit
    deploy
    ;
}