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