gunk-dev/the-valley

flake.nix

source75d050a4e31bmain's published tip history
5.7 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 valley CLI's self-update on a user timer, for a home-manager
50 # user whose valley follows a branch of the-valley
51 # (programs.valley.selfUpdate).
52 homeManagerModules.valley = ./nix/home-module.nix;
53
54 # The knowledge lint, for any project that keeps a `.the-valley/` graph.
55 # This is the check's primary form: a consuming project takes this flake
56 # as an input and instantiates the derivation over its own source, so the
57 # check a policy names is supplied by the instance rather than written
58 # again by every project the policy covers (dcr-f41f718). A whole
59 # consuming flake is:
60 #
61 # {
62 # inputs.the-valley.url = "git+ssh://git@valley-host/~/the-valley";
63 # outputs =
64 # { self, the-valley }:
65 # {
66 # checks.x86_64-linux.knowledge-lint = the-valley.lib.knowledgeLint {
67 # system = "x86_64-linux";
68 # src = self;
69 # };
70 # };
71 # }
72 #
73 # There is no nixpkgs input in that flake on purpose: cue and python come
74 # from this flake's pinned nixpkgs, so every project in a group runs the
75 # same lint against the same toolchain. `root` names the graph directory
76 # for a project that keeps its graph somewhere other than `.the-valley/`.
77 lib.knowledgeLint =
78 {
79 system,
80 src,
81 root ? ".the-valley",
82 }:
83 import ./nix/knowledge-lint.nix {
84 inherit src root;
85 pkgs = pkgsFor system;
86 };
87
88 apps =
89 lib.genAttrs systems (
90 system:
91 let
92 packages = packagesFor system;
93 in
94 {
95 fmt = {
96 type = "app";
97 program = lib.getExe packages.prose-fmt;
98 };
99 attest = {
100 type = "app";
101 program = lib.getExe packages.attest;
102 };
103 integrator = {
104 type = "app";
105 program = lib.getExe packages.integrator;
106 };
107 identity = {
108 type = "app";
109 program = lib.getExe packages.identity;
110 };
111 sigverify = {
112 type = "app";
113 program = lib.getExe packages.sigverify;
114 };
115 }
116 )
117 // lib.genAttrs sigverifySystems (system: {
118 sigverify = {
119 type = "app";
120 program = lib.getExe (packagesFor system).sigverify;
121 };
122 });
123
124 packages =
125 lib.genAttrs systems (
126 system:
127 let
128 packages = packagesFor system;
129 in
130 {
131 inherit (packages)
132 valley
133 attest
134 integrator
135 identity
136 valleyhook
137 sigverify
138 valley-web
139 valley-web-publish
140 valley-read-coverage
141 ;
142 default = packages.valley;
143 }
144 )
145 // lib.genAttrs sigverifySystems (system: {
146 inherit (packagesFor system) sigverify;
147 })
148 // lib.genAttrs cliSystems (system: {
149 inherit (packagesFor system) valley;
150 });
151
152 checks =
153 lib.genAttrs systems (
154 system:
155 import ./nix/checks.nix {
156 inherit lib self system;
157 pkgs = pkgsFor system;
158 packages = packagesFor system;
159 }
160 )
161 // lib.genAttrs sigverifySystems (
162 system:
163 import ./nix/checks/sigverify.nix {
164 pkgs = pkgsFor system;
165 packages = packagesFor system;
166 }
167 );
168 };
169}