forked from nix-community/nixos-generators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnixos-generate.nix
41 lines (38 loc) · 1.04 KB
/
nixos-generate.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{ nixpkgs ? <nixpkgs>
, configuration ? <nixos-config>
, system ? builtins.currentSystem
, formatConfig
, flakeUri ? null
, flakeAttr ? null
}:
let
module = { lib, ... }: {
options = {
filename = lib.mkOption {
type = lib.types.str;
description = "Declare the path of the wanted file in the output directory";
default = "*";
};
formatAttr = lib.mkOption {
type = lib.types.str;
description = "Declare the default attribute to build";
};
};
};
# Will only get evaluated when used, so no worries
flake = builtins.getFlake flakeUri;
flakeSystem = flake.outputs.packages."${system}".nixosConfigurations."${flakeAttr}" or flake.outputs.nixosConfigurations."${flakeAttr}";
in
if flakeUri != null then
flakeSystem.override (attrs: {
modules = attrs.modules ++ [ module formatConfig ];
})
else
import "${toString nixpkgs}/nixos/lib/eval-config.nix" {
inherit system;
modules = [
module
formatConfig
configuration
];
}