_main.nix
1 # 2 # The directory is the kind signature. 3 # 4 { inputs, lib, ... }: 5 let 6 7 # TODO[b7r6]: !! clean this shit up !! 8 # :: t6 9 optional-attrs = lib.optionalAttrs; 10 11 # :: t8 12 # :: Any 13 # :: Any 14 # Import module indices by kind 15 flake-modules = import ./modules/flake/_index.nix { inherit inputs lib; }; 16 # :: "flake" 17 nixos-modules = import ./modules/nixos/_index.nix; 18 home-modules = import ./modules/home/_index.nix; 19 # :: Any 20 in 21 { 22 _class = "flake"; 23 24 # Required by flake-parts for perSystem 25 systems = import inputs.systems; 26 27 # ════════════════════════════════════════════════════════════════════════════ 28 # MODULES BY KIND 29 # 30 # flake.modules.<kind>.<name> for automatic _class validation 31 # ════════════════════════════════════════════════════════════════════════════ 32 33 flake.modules = { 34 35 flake = { 36 inherit (flake-modules) 37 build 38 buck2 39 build-standalone 40 default 41 default-with-demos 42 devshell 43 docs 44 formatter 45 full 46 lint 47 lre 48 nativelink 49 nix-conf 50 nixpkgs 51 nv-sdk 52 container 53 prelude 54 prelude-demos 55 shortlist 56 shortlist-standalone 57 std 58 options-only 59 ; 60 }; 61 62 nixosModules = nixos-modules; 63 64 home = home-modules; 65 }; 66 67 # ════════════════════════════════════════════════════════════════════════════ 68 # OVERLAYS 69 # 70 # A pure function from the world as it is to the world as it ought to be. 71 # ════════════════════════════════════════════════════════════════════════════ 72 73 flake.overlays = (import ./overlays inputs).flake.overlays; 74 75 # ════════════════════════════════════════════════════════════════════════════ 76 # LIB 77 # 78 # Pure functions. No pkgs, no system. 79 # ════════════════════════════════════════════════════════════════════════════ 80 81 flake.lib = import ./lib { inherit lib; } // { 82 # Buck2 builder - use from downstream flakes: 83 # packages.myapp = aleph.lib.buck2.build pkgs { target = "//src:myapp"; }; 84 buck2 = import ./lib/buck2.nix { inherit inputs; }; 85 }; 86 87 # ════════════════════════════════════════════════════════════════════════════ 88 # TEMPLATES 89 # ════════════════════════════════════════════════════════════════════════════ 90 91 flake.templates = { 92 default = { 93 path = ./templates/default; 94 description = "Standard project"; 95 }; 96 97 nv = { 98 path = ./templates/nv; 99 description = "NVIDIA/ML project"; 100 }; 101 102 buck2 = { 103 path = ./templates/buck2; 104 description = "Buck2 build system with hermetic Nix toolchains"; 105 }; 106 107 minimal = { 108 path = ./templates/minimal; 109 description = "Minimal flake"; 110 }; 111 112 dhall-configured = { 113 path = ./templates/dhall-configured; 114 description = "Dhall-typed configuration"; 115 }; 116 117 nickel-configured = { 118 path = ./templates/nickel-configured; 119 description = "Nickel-typed configuration"; 120 }; 121 # :: [t26] 122 }; 123 124 # ════════════════════════════════════════════════════════════════════════════ 125 # // internal 126 # ════════════════════════════════════════════════════════════════════════════ 127 128 imports = [ 129 flake-modules.buck2 130 flake-modules.build 131 flake-modules.container 132 flake-modules.devshell 133 flake-modules.docs 134 flake-modules.formatter 135 flake-modules.lint 136 flake-modules.lre 137 flake-modules.prelude 138 flake-modules.prelude-demos 139 flake-modules.shortlist 140 flake-modules.std 141 142 # nix2gpu.flakeModule must be imported before nativelink module 143 # (provides perSystem.nix2gpu options) 144 inputs.nix2gpu.flakeModule 145 flake-modules.nativelink 146 ]; 147 148 # Enable shortlist, LRE, and NativeLink containers for aleph itself 149 aleph.shortlist.enable = true; 150 aleph.lre.enable = true; 151 aleph.nativelink.enable = true; 152 153 "perSystem" = 154 { 155 pkgs, 156 system, 157 ... 158 }: 159 let 160 # NativeLink from inputs (for LRE) 161 nativelink = inputs.nativelink.packages.${system}.default; 162 in 163 { 164 165 # Wire up shortlist paths to buck2 config 166 buck2.shortlist = { 167 fmt = "${pkgs.fmt}"; 168 "fmt_dev" = "${pkgs.fmt.dev}"; 169 "zlib_ng" = "${pkgs.zlib-ng}"; 170 catch2 = "${pkgs.catch2_3}"; 171 "catch2_dev" = "${pkgs.catch2_3.dev or pkgs.catch2_3}"; 172 spdlog = "${pkgs.spdlog}"; 173 "spdlog_dev" = "${pkgs.spdlog.dev or pkgs.spdlog}"; 174 mdspan = "${pkgs.mdspan}"; 175 rapidjson = "${pkgs.rapidjson}"; 176 "nlohmann_json" = "${pkgs.nlohmann_json}"; 177 libsodium = "${pkgs.libsodium}"; 178 "libsodium_dev" = "${pkgs.libsodium.dev or pkgs.libsodium}"; 179 }; 180 181 packages = { 182 aleph-lint = pkgs.callPackage ./packages/aleph-lint.nix { }; 183 184 # Expose nix-compile CLI 185 nix-compile = pkgs.aleph.nix-compile.cli; 186 187 # Armitage - daemon-free Nix operations via Buck2 188 armitage = inputs.self.lib.buck2.build pkgs { 189 src = inputs.self; 190 target = "//src/armitage:armitage"; 191 }; 192 193 armitage-proxy = inputs.self.lib.buck2.build pkgs { 194 src = inputs.self; 195 target = "//src/armitage:armitage-proxy"; 196 }; 197 } 198 // optional-attrs (pkgs ? mdspan) { inherit (pkgs) mdspan; } 199 // optional-attrs (system == "x86_64-linux" || system == "aarch64-linux") ( 200 optional-attrs (pkgs ? llvm-git) { inherit (pkgs) llvm-git; } 201 // optional-attrs (pkgs ? nvidia-sdk) { inherit (pkgs) nvidia-sdk; } 202 ) 203 // optional-attrs (nativelink != null) { 204 inherit nativelink; 205 }; 206 207 checks = import ./checks/default.nix { inherit pkgs system lib; }; 208 209 # nix2gpu requires explicit empty default (upstream bug - no default in option) 210 nix2gpu = { }; 211 }; 212 213 aleph.devshell = { 214 enable = true; 215 nv.enable = true; 216 straylight-nix.enable = true; 217 }; 218 219 aleph.nixpkgs.nv.enable = true; 220 221 # Buck2 build system integration 222 aleph.build = { 223 enable = true; 224 225 prelude.enable = true; 226 remote.enable = true; # n.b. remote execution is currently with `fly.io`... 227 228 toolchain = { 229 # n.b. package list is in `nix/modules/flake/build/options.nix` default... 230 231 cxx.enable = true; 232 nv.enable = true; 233 haskell.enable = true; 234 rust.enable = true; 235 lean.enable = true; 236 python.enable = true; 237 }; 238 }; 239 240 aleph.docs = { 241 enable = true; 242 title = "// aleph // prelude"; 243 description = "A specification for reproducible, composable infrastructure on Nix"; 244 theme = "ono-sendai"; 245 modules = [ flake-modules.options-only ]; 246 }; 247 }