nixos/options/copySysConf.nix

49 lines
1.1 KiB
Nix
Raw Normal View History

2019-04-18 07:40:47 +02:00
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.system.copySysConf;
cfgPath = ../.;
copySysConf = if !(isStorePath cfgPath) then pkgs.stdenv.mkDerivation rec {
2019-04-18 07:40:47 +02:00
name = "NixOS_Configuration-${version}";
version = commitIdFromGitRepo (cfgPath + "/.git");
2019-04-18 07:40:47 +02:00
src = cleanSource cfgPath;
2019-04-18 07:40:47 +02:00
installPhase = ''
cp -R ./. $out
'';
} else (builtins.toPath ../.);
2019-04-18 07:40:47 +02:00
in {
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"
];
};
};
}