2023-09-11 20:23:04 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2024-11-20 20:32:38 +01:00
|
|
|
with lib;
|
|
|
|
let
|
2019-04-18 07:40:47 +02:00
|
|
|
cfg = config.system.copySysConf;
|
2019-04-18 09:14:39 +02:00
|
|
|
cfgPath = ../.;
|
2023-09-11 20:23:04 +02:00
|
|
|
copySysConf =
|
2024-11-20 20:32:38 +01:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
}
|
2024-11-20 20:32:38 +01:00
|
|
|
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 {
|
2019-07-11 12:38:37 +02:00
|
|
|
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"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|