about summary refs log tree commit diff
path: root/pkgs/profpatsch/deploy.nix
blob: c6f7b556b38b57daf10ca305f39194aaddd7516e (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
# 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" ]
      ;

  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"

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

    ${bins.nix-copy-closure} \
      --to "ssh://$MACHINE?compress=true" \
      --use-substitutes \
      "$OUT_LINK"


    ${bins.ssh} \
      "root@$MACHINE" \
      "$(${bins.realpath} $OUT_LINK)/bin/switch-to-configuration" \
      "switch"
  '';

in {
  inherit
    deploy
    ;
}