gunk-dev/the-valley

flake.nix

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