-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
150 lines (132 loc) · 5.45 KB
/
flake.nix
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
inputs.disko.url = "github:nix-community/disko";
inputs.disko.inputs.nixpkgs.follows = "nixpkgs";
outputs = { nixpkgs, self, ... } @inputs:
let
pkgsArgs = {
overlays = [ self.overlays.default ];
config.allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [
"vault"
"vault-bin"
];
};
in
{
overlays.default = (final: prev: {
packit = final.callPackage ./packages/packit { };
outpack_server = final.callPackage ./packages/outpack_server { };
packit-app = final.callPackage ./packages/packit/packit-app.nix { };
packit-api = final.callPackage ./packages/packit/packit-api.nix { };
fetch-secrets = final.writers.writePython3Bin "fetch-secrets"
{
libraries = [ final.python3.pkgs.hvac ];
} ./scripts/fetch-secrets.py;
});
nixosConfigurations.wpia-packit = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./machines/wpia-packit.nix
./hardware-configuration.nix
{ nixpkgs = pkgsArgs; }
];
};
nixosConfigurations.wpia-packit-private = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./machines/wpia-packit-private.nix
./hardware-configuration.nix
{ nixpkgs = pkgsArgs; }
];
};
packages.x86_64-linux =
let pkgs = import nixpkgs ({ system = "x86_64-linux"; } // pkgsArgs);
in {
inherit (pkgs) outpack_server packit-app packit-api packit fetch-secrets;
default = self.nixosConfigurations.wpia-packit.config.system.build.toplevel;
deploy = pkgs.writeShellApplication {
name = "deploy-wpia-packit";
runtimeInputs = [ pkgs.nixos-rebuild ];
text = ''
nixos-rebuild switch \
--flake .#wpia-packit \
--target-host [email protected] \
--use-substitutes
'';
};
deploy-private = pkgs.writeShellApplication {
name = "deploy-wpia-packit-private";
runtimeInputs = [ pkgs.nixos-rebuild ];
text = ''
nixos-rebuild switch \
--flake .#wpia-packit-private \
--target-host [email protected] \
--use-substitutes
'';
};
update-ssh-keys = pkgs.writeShellApplication {
name = "update-ssh-keys";
runtimeInputs = [ pkgs.curl ];
text = builtins.readFile ./scripts/update-ssh-keys.sh;
};
diff = pkgs.writeShellApplication {
name = "diff";
runtimeInputs = [ pkgs.nix pkgs.nix-diff ];
text = ''
current=$(ssh [email protected] readlink /run/current-system)
nix-copy-closure --from [email protected] "$current"
# In theory .drvPath should allow us to use string interpolation
# instead of re-evaluating the flake, but for some reason it
# pulls all the build-time dependencies.
target=$(nix path-info --derivation .#nixosConfigurations.wpia-packit.config.system.build.toplevel)
nix-diff "$@" "$current" "$target"
'';
};
update = pkgs.writers.writePython3Bin "update" { } ./scripts/update.py;
start-vm = pkgs.writeShellApplication {
name = "start-vm";
runtimeInputs = [ pkgs.vault-bin ];
text =
let vaultUrl = self.nixosConfigurations.wpia-packit.config.vault.url;
in ''
token=$(vault print token)
if [[ -z $token ]]; then
echo "Logging in to ${vaultUrl}"
token=$(env VAULT_ADDR="${vaultUrl}" vault login -method=github -field=token)
fi
exec ${nixpkgs.lib.getExe self.nixosConfigurations.wpia-packit.config.system.build.vm} \
-fw_cfg name=opt/vault-token,string="$token" "$@"
'';
};
start-vm-private = pkgs.writeShellApplication {
name = "start-vm-private";
runtimeInputs = [ pkgs.vault-bin ];
text =
let vaultUrl = self.nixosConfigurations.wpia-packit-private.config.vault.url;
in ''
token=$(vault print token)
if [[ -z $token ]]; then
echo "Logging in to ${vaultUrl}"
token=$(env VAULT_ADDR="${vaultUrl}" vault login -method=github -field=token)
fi
exec ${nixpkgs.lib.getExe self.nixosConfigurations.wpia-packit-private.config.system.build.vm} \
-fw_cfg name=opt/vault-token,string="$token" "$@"
'';
};
vm-test = self.checks.x86_64-linux.default.driver;
};
checks.x86_64-linux.default =
let pkgs = import nixpkgs ({ system = "x86_64-linux"; } // pkgsArgs);
in pkgs.callPackage ./tests { inherit inputs; };
devShells.x86_64-linux.default =
let pkgs = import nixpkgs ({ system = "x86_64-linux"; } // pkgsArgs);
in pkgs.mkShell {
buildInputs = [
pkgs.nix-prefetch-github
pkgs.nixos-rebuild
];
};
};
}