summaryrefslogtreecommitdiffstats
path: root/krebs/krops.nix
blob: c2d26812cae6581c6b11eba0bbdfaae69fd5da0f (plain)
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
55
56
57
58
59
60
61
62
63
{ name }: rec {

  krops = builtins.fetchGit {
    url = https://cgit.krebsco.de/krops/;
    rev = "4e466eaf05861b47365c5ef46a31a188b70f3615";
  };

  lib = import "${krops}/lib";

  # TODO document why pkgs should be used like this
  pkgs = import "${krops}/pkgs" {};

  krebs-source = {
    nixpkgs.git = {
      ref = "e42c07d78a1fefc2d91f11f00e938253b3618a3b";
      url = https://github.com/NixOS/nixpkgs;
    };
    stockholm.file = toString ../.;
    stockholm-version.pipe = toString (pkgs.writeDash "${name}-version" ''
      set -efu
      cd $HOME/stockholm
      V=$(${pkgs.coreutils}/bin/date +%y.%m)
      if test -d .git; then
        V=$V.git.$(${pkgs.git}/bin/git describe --always --dirty)
        case $V in (*-dirty)
          V=$V@''${HOSTNAME-$(${pkgs.nettools}/bin/hostname)}
        esac
      fi
      printf %s "$V"
    '');
  };

  source ={ test }: lib.evalSource [
    krebs-source
    {
      nixos-config.symlink = "stockholm/krebs/1systems/${name}/config.nix";
      secrets =
        if test
          then {
            file = toString <stockholm/krebs/0tests/data/secrets>;
          }
          else {
            pass = {
              dir = "${lib.getEnv "HOME"}/brain";
              name = "krebs-secrets/${name}";
            };
          }
        ;
    }
  ];

  # usage: $(nix-build --no-out-link --argstr name HOSTNAME -A deploy)
  deploy = pkgs.krops.writeDeploy "${name}-deploy" {
    source = source { test = false; };
    target = "root@${name}/var/src";
  };

  # usage: $(nix-build --no-out-link --argstr name HOSTNAME -A test)
  test = pkgs.krops.writeTest "${name}-test" {
    source = source { test = true; };
    target = "${lib.getEnv "HOME"}/tmp/${name}-krops-test-src";
  };
}