|
6 | 6 |
|
7 | 7 | # Bin dependency |
8 | 8 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
| 9 | + inputs.nixos.url = "github:NixOS/nixpkgs/nixos-21.11"; |
9 | 10 |
|
10 | | - outputs = { self, nixpkgs, nixlib }: |
| 11 | + outputs = { self, nixpkgs, nixos, nixlib }@inputs: |
11 | 12 |
|
12 | 13 | # Library modules (depend on nixlib) |
13 | 14 | rec { |
|
18 | 19 | value.imports = [ (./formats + "/${file}") ./format-module.nix ]; |
19 | 20 | }) (builtins.readDir ./formats); |
20 | 21 |
|
21 | | - # example usage in flakes: |
22 | | - # outputs = { self, nixpkgs, nixos-generators, ...}: { |
23 | | - # vmware = nixos-generators.nixosGenerate { |
24 | | - # pkgs = nixpkgs.legacyPackages.x86_64-linux; |
25 | | - # modules = [./configuration.nix]; |
26 | | - # format = "vmware"; |
27 | | - # }; |
28 | | - # } |
29 | | - nixosGenerate = { pkgs, format, specialArgs ? { }, modules ? [ ] }: |
30 | | - let |
| 22 | + nixosGenerate' = { |
| 23 | + format |
| 24 | + , system |
| 25 | + , nixpkgs ? inputs.nixpkgs |
| 26 | + , pkgs ? nixpkgs.legacyPackages.${system} |
| 27 | + , specialArgs ? { } |
| 28 | + , modules ? [ ] |
| 29 | + }: |
| 30 | + let |
31 | 31 | formatModule = builtins.getAttr format nixosModules; |
32 | 32 | image = nixpkgs.lib.nixosSystem { |
33 | 33 | inherit pkgs specialArgs; |
|
36 | 36 | formatModule |
37 | 37 | ] ++ modules; |
38 | 38 | }; |
39 | | - in |
| 39 | + in assert system == pkgs.system; |
40 | 40 | image.config.system.build.${image.config.formatAttr}; |
41 | 41 |
|
| 42 | + # example usage in flakes: |
| 43 | + # outputs = { self, nixpkgs, nixos-generators, ...}: { |
| 44 | + # vmware = nixos-generators.nixosGenerate { |
| 45 | + # pkgs = nixpkgs.legacyPackages.x86_64-linux; |
| 46 | + # modules = [./configuration.nix]; |
| 47 | + # format = "vmware"; |
| 48 | + # }; |
| 49 | + # } |
| 50 | + nixosGenerate = { pkgs, format, specialArgs ? { }, modules ? [ ] }: |
| 51 | + nixosGenerate' { |
| 52 | + system = pkgs.system; |
| 53 | + inherit pkgs format specialArgs modules; |
| 54 | + }; |
42 | 55 | } |
43 | 56 |
|
44 | 57 | // |
45 | 58 |
|
46 | | - |
47 | 59 | # Binary and Devshell outputs (depend on nixpkgs) |
48 | 60 | ( |
49 | 61 | let |
|
90 | 102 | }); |
91 | 103 |
|
92 | 104 | defaultApp = forAllSystems (system: self.apps."${system}".nixos-generate); |
| 105 | + |
| 106 | + checks = let |
| 107 | + # No way to limit `nix flake check` to a subset of supported systems; |
| 108 | + # see https://github.com/NixOS/nix/issues/6398. |
| 109 | + forCheckSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ]; |
| 110 | + |
| 111 | + checksForNixpkgs = |
| 112 | + system: |
| 113 | + { |
| 114 | + input, |
| 115 | + id, |
| 116 | + modules ? (fetchModules system id) |
| 117 | + }: |
| 118 | + let |
| 119 | + pkgs = input.legacyPackages.${system}; |
| 120 | + generateFormat = format: self.nixosGenerate' { |
| 121 | + inherit format system pkgs; |
| 122 | + nixpkgs = input; |
| 123 | + }; |
| 124 | + #formatModules = builtins.removeAttrs self.nixosModules exclude; |
| 125 | + in nixlib.lib.mapAttrs' (format: _: let |
| 126 | + name = "${format}-${id}"; |
| 127 | + diag = ''evaluating format "${format}" using nixpkgs input "${id}" on system "${system}"''; |
| 128 | + value = nixlib.lib.trace diag (generateFormat format); |
| 129 | + in { |
| 130 | + inherit name value; |
| 131 | + }) modules; |
| 132 | + |
| 133 | + fetchModules = let |
| 134 | + excludeCommon = [ |
| 135 | + # error: |
| 136 | + # Failed assertions: |
| 137 | + # - Mountpoint '/': 'autoResize = true' is not supported for 'fsType = "auto"': fsType has to be explicitly set and only the ext filesystems and f2fs support it. |
| 138 | + "cloudstack" |
| 139 | + |
| 140 | + # error (ignored): error: cannot look up '<nixpkgs/nixos/lib/make-system-tarball.nix>' in pure evaluation mode (use '--impure' to override) |
| 141 | + # |
| 142 | + # at /nix/store/0b099b46lb9dmhwzyc2zgjk8lp8d9rfq-source/kexec/kexec.nix:42:49: |
| 143 | + # |
| 144 | + # 41| ''; |
| 145 | + # 42| system.build.kexec_tarball = pkgs.callPackage <nixpkgs/nixos/lib/make-system-tarball.nix> { |
| 146 | + # | ^ |
| 147 | + # 43| storeContents = [ |
| 148 | + "kexec" |
| 149 | + "kexec-bundle" |
| 150 | + ]; |
| 151 | + |
| 152 | + excludeNixpkgs = [ |
| 153 | + # error: path '/nix/store/0bsydzh62cn1by07j5cjy28crbnbc5wz-google-guest-configs-20211116.00.drv' is not valid) |
| 154 | + "gce" |
| 155 | + |
| 156 | + # Compilation error in some prerequisite or other. |
| 157 | + "proxmox" |
| 158 | + ]; |
| 159 | + |
| 160 | + excludeNixos = [ |
| 161 | + # error: getting status of '/nix/store/<...>/nixos/modules/virtualisation/kubevirt.nix': No such file or directory |
| 162 | + "kubevirt" |
| 163 | + |
| 164 | + # error: getting status of '/nix/store/<...>/nixos/modules/virtualisation/proxmox-lxc.nix': No such file or directory |
| 165 | + "proxmox-lxc" |
| 166 | + ]; |
| 167 | + |
| 168 | + aarch64Only = [ "sd-aarch64" "sd-aarch64-installer" ]; |
| 169 | + |
| 170 | + baseModules = builtins.removeAttrs self.nixosModules excludeCommon; |
| 171 | + nixpkgsModules = builtins.removeAttrs baseModules excludeNixpkgs; |
| 172 | + nixosModules = builtins.removeAttrs baseModules excludeNixos; |
| 173 | + |
| 174 | + matrix = { |
| 175 | + "x86_64-linux" = { |
| 176 | + "nixpkgs" = builtins.removeAttrs nixpkgsModules aarch64Only; |
| 177 | + "nixos" = builtins.removeAttrs nixosModules aarch64Only; |
| 178 | + }; |
| 179 | + |
| 180 | + "aarch64-linux" = { |
| 181 | + "nixpkgs" = nixlib.lib.getAttrs aarch64Only nixpkgsModules; |
| 182 | + "nixos" = nixlib.lib.getAttrs aarch64Only nixosModules; |
| 183 | + }; |
| 184 | + }; |
| 185 | + in system: id: matrix.${system}.${id}; |
| 186 | + in |
| 187 | + forCheckSystems (system: let |
| 188 | + checksForNixpkgs' = checksForNixpkgs system; |
| 189 | + |
| 190 | + nixpkgsChecks = checksForNixpkgs' { |
| 191 | + input = nixpkgs; |
| 192 | + id = "nixpkgs"; |
| 193 | + }; |
| 194 | + |
| 195 | + nixosChecks = checksForNixpkgs' { |
| 196 | + input = nixos; |
| 197 | + id = "nixos"; |
| 198 | + }; |
| 199 | + in nixpkgsChecks // nixosChecks); |
93 | 200 | } |
94 | 201 | ); |
95 | 202 | } |
0 commit comments