From 82028fd0e14e2c36de2893cd26421d1383b4160c Mon Sep 17 00:00:00 2001 From: derped Date: Thu, 18 Apr 2019 07:40:47 +0200 Subject: [PATCH] Added copySysConf module. --- configuration.nix | 2 +- machines/Lilim/options.nix | 6 +++++ options/copySysConf.nix | 49 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 options/copySysConf.nix diff --git a/configuration.nix b/configuration.nix index 3f0093b..bec2ee7 100644 --- a/configuration.nix +++ b/configuration.nix @@ -3,7 +3,7 @@ with lib; let - machinePath = (builtins.toPath ("/etc/nixos/machines/" + (fileContents /secret/hostName))); + machinePath = (builtins.toPath ( ./machines + ("/" + (fileContents /secret/hostName)))); machineConf = machinePath + "/configuration.nix"; machineOpts = machinePath + "/options.nix"; in { diff --git a/machines/Lilim/options.nix b/machines/Lilim/options.nix index f23829b..f5eb911 100644 --- a/machines/Lilim/options.nix +++ b/machines/Lilim/options.nix @@ -5,6 +5,7 @@ with lib; { imports = [ ../../options/machine.nix + ../../options/copySysConf.nix ]; config.machine = { @@ -43,4 +44,9 @@ with lib; allowedTCPPortRanges = [ { from = 1714; to = 1764; } ]; }; }; + + config.system.copySysConf = { + enable = true; + addToNixPath = false; + }; } diff --git a/options/copySysConf.nix b/options/copySysConf.nix new file mode 100644 index 0000000..d848683 --- /dev/null +++ b/options/copySysConf.nix @@ -0,0 +1,49 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.system.copySysConf; + copySysConf = pkgs.stdenv.mkDerivation rec { + srcPath = ../.; + name = "NixOS_Configuration-${version}"; + version = "0.1"; + # this does not work yet for some reason + # version = commitIdFromGitRepo "${srcPath}/.git"; + + 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" + ]; + }; + }; +}