Skip to content

Commit b39f561

Browse files
committed
chore: cleanup flake and add nix tests for sops
1 parent a802a29 commit b39f561

File tree

8 files changed

+107
-19
lines changed

8 files changed

+107
-19
lines changed

flake.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@
165165
};
166166
in
167167
{
168-
packages.default = self.packages."${system}".deploy-rs;
168+
packages.default = self.packages.${system}.deploy-rs;
169169
packages.deploy-rs = pkgs.deploy-rs.deploy-rs;
170170

171-
apps.default = self.apps."${system}".deploy-rs;
171+
apps.default = self.apps.${system}.deploy-rs;
172172
apps.deploy-rs = {
173173
type = "app";
174-
program = "${self.packages."${system}".default}/bin/deploy";
174+
program = "${self.packages.${system}.default}/bin/deploy";
175175
};
176176

177177
devShells.default = pkgs.mkShell {

nix/tests/default.nix

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let
2020
done <$refs
2121
'';
2222

23-
mkTest = { name ? "", user ? "root", flakes ? true, isLocal ? true, deployArgs }: let
23+
mkTest = { name ? "", user ? "root", flakes ? true, isLocal ? true, sops ? false, deployArgs }: let
2424
nodes = {
2525
server = { nodes, ... }: {
2626
imports = [
@@ -36,7 +36,7 @@ let
3636
};
3737
client = { nodes, ... }: {
3838
imports = [ (import ./common.nix { inherit inputs pkgs flakes; }) ];
39-
environment.systemPackages = [ pkgs.deploy-rs.deploy-rs ];
39+
environment.systemPackages = [ pkgs.deploy-rs.deploy-rs ] ++ lib.optionals sops [ pkgs.sops ];
4040
# nix evaluation takes a lot of memory, especially in non-flake usage
4141
virtualisation.memorySize = lib.mkForce 4096;
4242
virtualisation.additionalPaths = lib.optionals isLocal [
@@ -97,6 +97,14 @@ let
9797
client.succeed("cp ${./server.nix} ./server.nix")
9898
client.succeed("cp ${./common.nix} ./common.nix")
9999
client.succeed("cp ${serverNetworkJSON} ./network.json")
100+
101+
# Prepare sops keys
102+
client.succeed("cp ${./sops/.sops.yaml} ./.sops.yaml")
103+
client.succeed("cp ${./sops/password.yaml} ./password.yaml")
104+
# this is where sops looks for private keys
105+
client.succeed("mkdir -p /root/.config/sops/age/")
106+
client.succeed("cp ${./sops/age_private.txt} /root/.config/sops/age/keys.txt")
107+
100108
client.succeed("nix --extra-experimental-features flakes flake lock")
101109
102110
# Setup SSH key
@@ -115,6 +123,9 @@ let
115123
# Make sure the hello and figlet packages are missing
116124
server.fail("su ${user} -l -c 'hello | figlet'")
117125
126+
# Create a missing directory
127+
server.succeed("mkdir -p /root/.local/state/nix/profiles")
128+
118129
# Deploy to the server
119130
client.succeed("deploy ${deployArgs}")
120131
@@ -173,4 +184,16 @@ in {
173184
flakes = true;
174185
deployArgs = "--file . --targets server";
175186
};
187+
sops = mkTest {
188+
name = "sops";
189+
user = "sops";
190+
sops = true;
191+
deployArgs = "-s .#sops";
192+
};
193+
sops-override-arguments = mkTest {
194+
name = "sops-override-arguments";
195+
user = "sops";
196+
sops = true;
197+
deployArgs = "-s .#server --sudo-file ./password.yaml --sudo-secret passwords/sops --ssh-user sops";
198+
};
176199
}

nix/tests/deploy-flake.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"-o" "StrictHostKeyChecking=no"
3737
"-o" "StrictHostKeyChecking=no"
3838
];
39-
profiles.system.path = deploy-rs.lib."${system}".activate.nixos self.nixosConfigurations.server;
39+
profiles.system.path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.server;
4040
};
4141
server-override = {
4242
hostname = "override";
@@ -46,7 +46,7 @@
4646
sshOpts = [ ];
4747
confirmTimeout = 0;
4848
activationTimeout = 0;
49-
profiles.system.path = deploy-rs.lib."${system}".activate.nixos self.nixosConfigurations.server;
49+
profiles.system.path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.server;
5050
};
5151
profile = {
5252
hostname = "server";
@@ -67,6 +67,14 @@
6767
in deploy-rs.lib.${system}.activate.custom activateProfile "$PROFILE/bin/activate";
6868
};
6969
};
70+
sops = {
71+
hostname = "server";
72+
sshUser = "sops";
73+
sshOpts = [ "-o" "StrictHostKeyChecking=no" ];
74+
sudoFile = ./password.yaml;
75+
sudoSecret = "passwords/sops";
76+
profiles.system.path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.server;
77+
};
7078
};
7179
};
7280
}

nix/tests/server.nix

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,49 @@
44
{ pkgs, ... }:
55
{
66
nix.settings.trusted-users = [ "deploy" ];
7-
users = let
8-
inherit (import "${pkgs.path}/nixos/tests/ssh-keys.nix" pkgs) snakeOilPublicKey;
9-
in {
10-
mutableUsers = false;
11-
users = {
12-
deploy = {
13-
password = "";
14-
isNormalUser = true;
15-
createHome = true;
16-
openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
7+
users =
8+
let
9+
inherit (import "${pkgs.path}/nixos/tests/ssh-keys.nix" pkgs) snakeOilPublicKey;
10+
in
11+
{
12+
mutableUsers = false;
13+
users = {
14+
deploy = {
15+
password = "";
16+
isNormalUser = true;
17+
createHome = true;
18+
group = "deploy";
19+
extraGroups = [ "wheel" ]; # need wheel for `sudo su`
20+
openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
21+
};
22+
sops = {
23+
password = "rootIsAGoodRootPassword";
24+
isNormalUser = true;
25+
createHome = true;
26+
group = "sops";
27+
extraGroups = [ "wheel" ]; # need wheel for `sudo su`
28+
openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
29+
};
30+
root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
31+
};
32+
groups = {
33+
deploy = { };
34+
sops = { };
1735
};
18-
root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
1936
};
20-
};
37+
38+
# deploy does not need a password for sudo
39+
security.sudo.extraRules = [
40+
{
41+
groups = [ "deploy" ];
42+
commands = [
43+
{
44+
command = "ALL";
45+
options = [ "NOPASSWD" ];
46+
}
47+
];
48+
}
49+
];
2150
services.openssh.enable = true;
2251
virtualisation.writableStore = true;
2352
}

nix/tests/sops/.sops.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
keys:
2+
- &primary age179s8jnppgy9kwakmva8av6frpnhgg9myrvk3xlfpanmhvvzyh96sdygfcm
3+
creation_rules:
4+
- path_regex: password.yaml
5+
key_groups:
6+
- age:
7+
- *primary

nix/tests/sops/age_private.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# created: 2025-06-05T11:36:08+02:00
2+
# public key: age179s8jnppgy9kwakmva8av6frpnhgg9myrvk3xlfpanmhvvzyh96sdygfcm
3+
AGE-SECRET-KEY-1L8HTRL2THGGZLXQQDTDLDG0U8EL4RSSAMVT9RYUG5JWPUJW49N9QS0EFSZ

nix/tests/sops/age_public.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
age179s8jnppgy9kwakmva8av6frpnhgg9myrvk3xlfpanmhvvzyh96sdygfcm

nix/tests/sops/password.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
passwords:
2+
sops: ENC[AES256_GCM,data:DXcCPJcsVWA4oja7DFCUERRLR98rcbY=,iv:NaqB7ogUGJUAg0wg4J1xsUEEX48lbDUhRNfuRlBp5YI=,tag:e+D9XwazhhHhqPefepUbrA==,type:str]
3+
sops:
4+
age:
5+
- recipient: age179s8jnppgy9kwakmva8av6frpnhgg9myrvk3xlfpanmhvvzyh96sdygfcm
6+
enc: |
7+
-----BEGIN AGE ENCRYPTED FILE-----
8+
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBMckNqSWF3MUpNOU91T2Zh
9+
dU9ZQlozVWd3bnhsakZRSlFxcGVCZ3Z1dGpvCkVtbkhDNkNhTU5PUHhuVm5BaTJa
10+
dGRhU0c5MmQ2bVdyc1JnVVB0aCt1YW8KLS0tIHd4NWlDZEQvdEhxb2lVaUtmSktO
11+
MDExNzUwUG5KZ2JyZHhKTmFLZEpleWcKDNxV1CKbEeQ4ixX4PMSj60egj31bN2KG
12+
Zm0wfO8UtuGkLVcPKLL7jUhgQXzN9jHg/fDzT11tTnmFaEwtfhHzWg==
13+
-----END AGE ENCRYPTED FILE-----
14+
lastmodified: "2025-06-06T17:18:18Z"
15+
mac: ENC[AES256_GCM,data:A6ee/YUtR65KK2697QLKzKgGvaGUZZjgv5Ie2fUBnxtnTf5aWx0E+2mY1krbwv02Wr9HAr/BJnSKqvFrANEA2x58Ijgin+g8nVgspxshTgG1TPXL1+cG724kxheiU0TRnmBwumyEsVlpSjxbyeEDngH4oB9rIuc33Sp7Z1PAXpA=,iv:fgRXSEDjYyjRxwTN1/ZIokgdzE8wjpUALzEUAdWhUIQ=,tag:4lR0+tp/EqXB4qqv4UhxkQ==,type:str]
16+
unencrypted_suffix: _unencrypted
17+
version: 3.10.2

0 commit comments

Comments
 (0)