gunk-dev/the-valley

flake.nix

sourcef0de1b6b5b5dmain's published tip history
6.0 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 apps =
94 lib.genAttrs systems (
95 system:
96 let
97 packages = packagesFor system;
98 in
99 {
100 fmt = {
101 type = "app";
102 program = lib.getExe packages.prose-fmt;
103 };
104 attest = {
105 type = "app";
106 program = lib.getExe packages.attest;
107 };
108 integrator = {
109 type = "app";
110 program = lib.getExe packages.integrator;
111 };
112 identity = {
113 type = "app";
114 program = lib.getExe packages.identity;
115 };
116 sigverify = {
117 type = "app";
118 program = lib.getExe packages.sigverify;
119 };
120 }
121 )
122 // lib.genAttrs sigverifySystems (system: {
123 sigverify = {
124 type = "app";
125 program = lib.getExe (packagesFor system).sigverify;
126 };
127 });
128
129 packages =
130 lib.genAttrs systems (
131 system:
132 let
133 packages = packagesFor system;
134 in
135 {
136 inherit (packages)
137 valley
138 attest
139 integrator
140 identity
141 valleyhook
142 sigverify
143 valley-web
144 valley-web-receive
145 valley-web-image
146 valley-web-publish
147 valley-read-coverage
148 ;
149 default = packages.valley;
150 }
151 )
152 // lib.genAttrs sigverifySystems (system: {
153 inherit (packagesFor system) sigverify;
154 })
155 // lib.genAttrs cliSystems (system: {
156 inherit (packagesFor system) valley;
157 });
158
159 checks =
160 lib.genAttrs systems (
161 system:
162 import ./nix/checks.nix {
163 inherit lib self system;
164 pkgs = pkgsFor system;
165 packages = packagesFor system;
166 }
167 )
168 // lib.genAttrs sigverifySystems (
169 system:
170 import ./nix/checks/sigverify.nix {
171 pkgs = pkgsFor system;
172 packages = packagesFor system;
173 }
174 );
175 };
176}