nixos-generators/nixos-generate.nix

42 lines
1.0 KiB
Nix
Raw Normal View History

{ nixpkgs ? <nixpkgs>
, configuration ? <nixos-config>
, system ? builtins.currentSystem
2020-10-23 18:54:01 +03:00
, formatConfig
, flakeUri ? null
, flakeAttr ? null
}:
let
module = { lib, ... }: {
options = {
2020-05-22 11:26:49 +03:00
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";
};
};
};
2020-10-23 18:54:01 +03:00
# 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
2020-10-23 18:54:01 +03:00
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
];
}