default.nix 1.54 KB
Newer Older
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
# Builds and deploys a configuraiton change
# 
# To build the configuration:
#
# ```sh
# $ nix build -f ../../ deploy.HOSTNAME
# ```
# where HOSTNAME is the hostname you wish to build the configuration for.
# Use `deploy.all` to build the configuration for all hosts at once
#
#
# To deploy the configuration:
#
# ```sh
# $ ./result MODE
# ```
# where MODE is one of the following:
# - `switch`
#   - Builds and activates the new configuration, and makes it the boot default.
# - `boot`
#   - Builds the new configuration and makes it the boot default (as with `switch`), but does not activate it.
#     That is, the system continues to run the previous configuration until the next reboot.
# - `test`
#   - Builds and activates the new configuration, but does not add it to the GRUB boot menu. Thus, if you reboot the
#     system (or if it crashes), you will automatically revert to the default configuration.
#
# There are some more commands that can be found in nixos-rebuild(8)
{ pkgs }:

with pkgs.lib;

let
  inherit (import ./hosts.nix { inherit pkgs; }) hosts groups;

in (
  mapAttrs (name: hosts: pkgs.writeScript "deploy-group-${name}" ''
    #!${pkgs.runtimeShell}
    export PATH=

    ${concatMapStrings (host: ''
      echo "deploying ${host.config.networking.hostName}..."
      ${host.config.system.build.deployScript} $1 &
      PID_LIST+=" $!"
    '') hosts}

    # FIXME: remove jobs from PIDLIST once they finish
    trap "kill $PID_LIST" SIGINT
    wait $PID_LIST
  '') groups
)
 // (mapAttrs (name: host: host.config.system.build.deployScript) hosts)