nixos/options/copySysConf.nix

56 lines
1.2 KiB
Nix
Raw Normal View History

2023-09-11 20:23:04 +02:00
{
config,
pkgs,
lib,
...
}:
with lib;
let
2019-04-18 07:40:47 +02:00
cfg = config.system.copySysConf;
cfgPath = ../.;
2023-09-11 20:23:04 +02:00
copySysConf =
if !(isStorePath cfgPath) then
2023-09-11 20:23:04 +02:00
pkgs.stdenv.mkDerivation rec {
name = "NixOS_Configuration-${version}";
version = commitIdFromGitRepo (cfgPath + "/.git");
2019-04-18 07:40:47 +02:00
2023-09-11 20:23:04 +02:00
src = cleanSource cfgPath;
2019-04-18 07:40:47 +02:00
2023-09-11 20:23:04 +02:00
installPhase = ''
cp -R ./. $out
'';
}
else
(builtins.toPath ../.);
in
{
2019-04-18 07:40:47 +02:00
options.system.copySysConf = {
enable = mkOption {
type = types.bool;
description = ''
Wether to copy the systems configuration.
'';
};
addToNixPath = mkOption {
type = types.bool;
description = ''
Use backup for nixos-rebuild.
'';
};
};
config = mkIf cfg.enable {
environment.variables = {
NIXOS_CONFIG_PATH = "${copySysConf}";
};
2019-04-18 07:40:47 +02:00
nix = mkIf cfg.addToNixPath {
# Do not use lib.optionals as it would override the default nixPath
nixPath = [
"nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
"nixos-config=${copySysConf}/configuration.nix"
"/nix/var/nix/profiles/per-user/root/channels"
];
};
};
}