-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
125 lines (112 loc) · 3.42 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
komapedia = {
url = "github:Die-KoMa/mediawiki";
inputs.nixpkgs.follows = "nixpkgs";
};
wat = {
url = "github:thelegy/wat";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
homemanager = {
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs";
};
yaner = {
url = "github:thelegy/yaner";
inputs = {
homemanager.follows = "homemanager";
nixpkgs-stable.follows = "nixpkgs";
nixpkgs.follows = "nixpkgs";
sops-nix.follows = "sops-nix";
wat.follows = "wat";
};
};
};
outputs =
flakes@{
wat,
nixpkgs,
sops-nix,
...
}:
let
inherit (nixpkgs.lib) attrValues concatLists concatStringsSep;
sopsPGPKeyDirs = [
./secrets/keys/users
./secrets/keys/hosts
];
rekey =
pkgs:
pkgs.writeShellScriptBin "sops-rekey" ''
${pkgs.findutils}/bin/find . -type f -regextype posix-extended -regex '.*/secrets(/.*)?.ya?ml' -exec ${pkgs.sops}/bin/sops updatekeys {} \;
'';
withPkgs = wat.lib.withPkgsFor [ "x86_64-linux" ] nixpkgs [ flakes.sops-nix.overlays.default ];
in
wat.lib.mkWatRepo flakes (
{ findModules, findMachines, ... }:
{
loadModules = concatLists [
[
flakes.homemanager.nixosModules.home-manager
flakes.sops-nix.nixosModules.sops
]
(attrValues flakes.komapedia.nixosModules)
(attrValues flakes.yaner.nixosModules)
];
loadOverlays = concatLists [ [ flakes.yaner.overlay ] ];
outputs = {
apps = withPkgs (
pkgs:
let
sops-wrapper = pkgs.writeShellScript "sops-wrapper" ''
export sopsPGPKeyDirs="${concatStringsSep " " sopsPGPKeyDirs}"
source ${pkgs.sops-import-keys-hook}/nix-support/setup-hook
sopsImportKeysHook
exec ${pkgs.sops}/bin/sops "$@"
'';
dnscontrol-wrapper = pkgs.writeShellScript "dnscontrol-wrapper" ''
cd ${./dns}
exec ${pkgs.sops}/bin/sops exec-env creds.yaml "${pkgs.dnscontrol}/bin/dnscontrol $@"
'';
in
{
sops-rekey = {
type = "app";
program = "${rekey pkgs}/bin/sops-rekey";
};
sops = {
type = "app";
program = "${sops-wrapper}";
};
dnscontrol = {
type = "app";
program = "${dnscontrol-wrapper}";
};
}
);
devShells = withPkgs (pkgs: rec {
sops = pkgs.mkShell {
name = "sops";
nativeBuildInputs = with pkgs; [
sops-import-keys-hook
ssh-to-pgp
(rekey pkgs)
];
inherit sopsPGPKeyDirs;
};
default = sops;
});
overlays.default = import ./pkgs flakes;
nixosModules = findModules [ "KoMa" ] ./modules;
nixosConfigurations = findMachines ./machines;
formatter = withPkgs (pkgs: pkgs.treefmt);
};
}
);
}