gunk-dev/the-valley

flake.nix

source6a7605f70901main's published tip history
7.1 KiB
1{
2 description = "the-valley: the CUE domain schema for a valley host, and the NixOS module that installs one";
3
4 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
5
6 outputs =
7 { self, nixpkgs }:
8 let
9 lib = nixpkgs.lib;
10 # Every package, app and check is offered for x86_64-linux, where the
11 # checks build and run them. Checks use import-from-derivation (the
12 # module's cue export), so they are only defined for the system that
13 # can actually build them here.
14 systems = [ "x86_64-linux" ];
15 # sigverify is also built and tested for aarch64-linux, because hosts
16 # such as Raspberry Pis verify their releases with it. Its checks need no
17 # import-from-derivation, so they are defined there too, and an
18 # aarch64 builder (or binfmt emulation) runs them. Nothing else here
19 # is offered on aarch64-linux, because nothing else is tested there.
20 sigverifySystems = [ "aarch64-linux" ];
21 # The client packages (clientPackages in nix/packages.nix: valley,
22 # valley-flow and klaus, approval, attest, identity and sigverify) and
23 # the formatter are also offered for aarch64-darwin, so a person or an
24 # agent can run them on a Mac. No Darwin machine runs this flake's
25 # checks, so nothing is built, tested or run for Darwin here. From
26 # x86_64-linux, valley-darwin-build compiles, links and vets each
27 # client program's Go for darwin/arm64, and valley-darwin-eval
28 # evaluates every Darwin package, app and formatter. The programs only
29 # a valley host runs are not offered on Darwin.
30 cliSystems = [ "aarch64-darwin" ];
31
32 pkgsFor = system: nixpkgs.legacyPackages.${system};
33
34 # What this flake builds (nix/packages.nix) and what it tests
35 # (nix/checks.nix). A flake says which outputs exist and what they are
36 # built from; what a package is and what a check does live in files.
37 packagesFor =
38 system:
39 import ./nix/packages.nix {
40 inherit lib;
41 pkgs = pkgsFor system;
42 # For the CLI's version stamp. A dirty tree has no rev, and nix
43 # gives its dirtyRev instead.
44 rev = self.rev or self.dirtyRev or null;
45 };
46 in
47 {
48 nixosModules.valley-host = ./nix/valley-host.nix;
49 nixosModules.default = self.nixosModules.valley-host;
50
51 # The web publisher on a timer (services.valley.webPublisher), beside
52 # the host module, whose repositories it reads.
53 nixosModules.web-publisher = ./nix/web-publisher.nix;
54
55 # The web export receiver and valley-web on a NixOS edge host
56 # (services.valley.webReceiver): two units over one state directory,
57 # the receiver writing it and valley-web reading it.
58 nixosModules.web-receiver = ./nix/web-receiver.nix;
59
60 # The valley CLI's self-update on a user timer, for a home-manager
61 # user whose valley follows a branch of the-valley
62 # (programs.valley.selfUpdate).
63 homeManagerModules.valley = ./nix/home-module.nix;
64
65 # The knowledge lint, for any project that keeps a `.the-valley/` graph.
66 # This is the check's primary form: a consuming project takes this flake
67 # as an input and instantiates the derivation over its own source, so the
68 # check a policy names is supplied by the instance rather than written
69 # again by every project the policy covers (dcr-f41f718). A whole
70 # consuming flake is:
71 #
72 # {
73 # inputs.the-valley.url = "git+ssh://git@valley-host/~/the-valley";
74 # outputs =
75 # { self, the-valley }:
76 # {
77 # checks.x86_64-linux.knowledge-lint = the-valley.lib.knowledgeLint {
78 # system = "x86_64-linux";
79 # src = self;
80 # };
81 # };
82 # }
83 #
84 # There is no nixpkgs input in that flake on purpose: cue and python come
85 # from this flake's pinned nixpkgs, so every project in a group runs the
86 # same lint against the same toolchain. `root` names the graph directory
87 # for a project that keeps its graph somewhere other than `.the-valley/`.
88 lib.knowledgeLint =
89 {
90 system,
91 src,
92 root ? ".the-valley",
93 }:
94 import ./nix/knowledge-lint.nix {
95 inherit src root;
96 pkgs = pkgsFor system;
97 };
98
99 # `nix fmt` runs the same program as `nix run .#fmt`.
100 formatter = lib.genAttrs (systems ++ cliSystems) (system: (packagesFor system).prose-fmt);
101
102 apps =
103 lib.genAttrs systems (
104 system:
105 let
106 packages = packagesFor system;
107 in
108 {
109 fmt = {
110 type = "app";
111 program = lib.getExe packages.prose-fmt;
112 };
113 attest = {
114 type = "app";
115 program = lib.getExe packages.attest;
116 };
117 integrator = {
118 type = "app";
119 program = lib.getExe packages.integrator;
120 };
121 identity = {
122 type = "app";
123 program = lib.getExe packages.identity;
124 };
125 approval = {
126 type = "app";
127 program = lib.getExe packages.approval;
128 };
129 sigverify = {
130 type = "app";
131 program = lib.getExe packages.sigverify;
132 };
133 }
134 )
135 // lib.genAttrs sigverifySystems (system: {
136 sigverify = {
137 type = "app";
138 program = lib.getExe (packagesFor system).sigverify;
139 };
140 })
141 // lib.genAttrs cliSystems (system: {
142 fmt = {
143 type = "app";
144 program = lib.getExe (packagesFor system).prose-fmt;
145 };
146 });
147
148 packages =
149 lib.genAttrs systems (
150 system:
151 let
152 packages = packagesFor system;
153 in
154 {
155 inherit (packages)
156 valley
157 attest
158 integrator
159 identity
160 approval
161 valleyhook
162 sigverify
163 valley-web
164 valley-web-receive
165 valley-web-image
166 valley-web-publish
167 valley-read-coverage
168 valley-flow
169 klaus
170 ;
171 default = packages.valley;
172 }
173 )
174 // lib.genAttrs sigverifySystems (system: {
175 inherit (packagesFor system) sigverify;
176 })
177 // lib.genAttrs cliSystems (
178 system:
179 let
180 packages = packagesFor system;
181 in
182 lib.genAttrs packages.clientPackages (name: packages.${name})
183 // {
184 default = packages.valley;
185 }
186 );
187
188 checks =
189 lib.genAttrs systems (
190 system:
191 import ./nix/checks.nix {
192 inherit lib self system;
193 pkgs = pkgsFor system;
194 packages = packagesFor system;
195 }
196 )
197 // lib.genAttrs sigverifySystems (
198 system:
199 import ./nix/checks/sigverify.nix {
200 pkgs = pkgsFor system;
201 packages = packagesFor system;
202 }
203 );
204 };
205}