| 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 programs (clientPrograms in nix/packages.nix: valley, |
| 22 | # klaus, approval, attest, identity and sigverify) and the formatter |
| 23 | # are also offered for aarch64-darwin, so a person or an agent can run |
| 24 | # them on a Mac. No Darwin machine runs this flake's checks, so nothing |
| 25 | # is built, tested or run for Darwin here. From x86_64-linux, |
| 26 | # valley-darwin-build compiles, links and vets each client program's |
| 27 | # Go for darwin/arm64, and valley-darwin-eval evaluates every Darwin |
| 28 | # package, app and formatter. The programs only a valley host runs |
| 29 | # 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 | klaus |
| 169 | ; |
| 170 | default = packages.valley; |
| 171 | } |
| 172 | ) |
| 173 | // lib.genAttrs sigverifySystems (system: { |
| 174 | inherit (packagesFor system) sigverify; |
| 175 | }) |
| 176 | // lib.genAttrs cliSystems ( |
| 177 | system: |
| 178 | let |
| 179 | packages = packagesFor system; |
| 180 | in |
| 181 | lib.genAttrs (lib.attrNames packages.clientPrograms) (name: packages.${name}) |
| 182 | // { |
| 183 | default = packages.valley; |
| 184 | } |
| 185 | ); |
| 186 | |
| 187 | checks = |
| 188 | lib.genAttrs systems ( |
| 189 | system: |
| 190 | import ./nix/checks.nix { |
| 191 | inherit lib self system; |
| 192 | pkgs = pkgsFor system; |
| 193 | packages = packagesFor system; |
| 194 | } |
| 195 | ) |
| 196 | // lib.genAttrs sigverifySystems ( |
| 197 | system: |
| 198 | import ./nix/checks/sigverify.nix { |
| 199 | pkgs = pkgsFor system; |
| 200 | packages = packagesFor system; |
| 201 | } |
| 202 | ); |
| 203 | }; |
| 204 | } |