nixos/options/copySysConf.nix

48 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;
copySysConf = pkgs.stdenv.mkDerivation rec {
srcPath = ../.;
name = "NixOS_Configuration-${version}";
2019-04-18 08:38:25 +02:00
version = commitIdFromGitRepo (srcPath + "/.git");
2019-04-18 07:40:47 +02:00
src = cleanSource srcPath;
installPhase = ''
cp -R ./. $out
'';
};
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 {
# probably don't need to add it to systemPackages
environment.systemPackages = [ copySysConf ];
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"
];
};
};
}