gunk-dev/the-valley

flake.nix

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