|
6 | 6 | , flakeAttr ? null |
7 | 7 | }: |
8 | 8 | let |
| 9 | + lib = (import nixpkgs { }).lib; |
| 10 | + |
9 | 11 | nixos-shell = import ./modules/nixos-shell.nix; |
10 | 12 | nixos-shell-config = import ./modules/nixos-shell-config.nix; |
11 | 13 |
|
12 | | - flake = builtins.getFlake flakeUri; |
13 | | - flakeSystem = flake.outputs.packages."${system}".nixosConfigurations."${flakeAttr}" or flake.outputs.nixosConfigurations."${flakeAttr}"; |
14 | | -in |
15 | | -if flakeUri != null then |
16 | | - flakeSystem.override |
17 | | - (attrs: { |
18 | | - modules = |
19 | | - let |
20 | | - nixosShellModules = |
21 | | - if flakeSystem ? options.nixos-shell then |
22 | | - [ nixos-shell-config ] |
23 | | - else |
24 | | - [ nixos-shell nixos-shell-config ]; |
25 | | - in |
26 | | - attrs.modules ++ nixosShellModules; |
27 | | - }) |
28 | | -else |
29 | | - import "${toString nixpkgs}/nixos/lib/eval-config.nix" { |
| 14 | + defaultTo = default: e: if e == null then default else e; |
| 15 | + |
| 16 | + getFlakeOutput = path: lib.attrByPath path null flake.outputs; |
| 17 | + |
| 18 | + mkShellSystem = config: import "${toString nixpkgs}/nixos/lib/eval-config.nix" { |
30 | 19 | inherit system; |
31 | 20 | modules = [ |
32 | | - configuration |
| 21 | + config |
33 | 22 | nixos-shell |
34 | 23 | nixos-shell-config |
35 | 24 | ]; |
36 | | - } |
| 25 | + }; |
| 26 | + |
| 27 | + flake = builtins.getFlake flakeUri; |
| 28 | + |
| 29 | + flakeSystem = defaultTo |
| 30 | + (getFlakeOutput [ "nixosConfigurations" "${flakeAttr}" ]) |
| 31 | + (getFlakeOutput [ "packages" "${system}" "nixosConfigurations" "${flakeAttr}" ]); |
| 32 | + |
| 33 | + flakeModule = getFlakeOutput [ "nixosModules" "${flakeAttr}" ]; |
| 34 | +in |
| 35 | +if flakeUri != null then |
| 36 | + if flakeSystem != null then |
| 37 | + flakeSystem.override |
| 38 | + (attrs: { |
| 39 | + modules = |
| 40 | + let |
| 41 | + nixosShellModules = |
| 42 | + if flakeSystem ? options.nixos-shell then |
| 43 | + [ nixos-shell-config ] |
| 44 | + else |
| 45 | + [ nixos-shell nixos-shell-config ]; |
| 46 | + in |
| 47 | + attrs.modules ++ nixosShellModules; |
| 48 | + }) |
| 49 | + else if flakeModule != null then |
| 50 | + mkShellSystem flakeModule |
| 51 | + else |
| 52 | + throw "cannot find flake attribute '${flakeUri}#${flakeAttr}'" |
| 53 | +else |
| 54 | + mkShellSystem configuration |
0 commit comments