about summary refs log tree commit diff
path: root/modules/profiles
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2015-12-01 15:24:13 +0100
committeraszlig <aszlig@redmoonstudios.org>2015-12-01 15:27:51 +0100
commit0d8c53a0ad23d684e475eb3add87d46aa7adadb0 (patch)
treefdc7e03a940db6c911c15febcb14553d250aea99 /modules/profiles
parentaf23241b165c01cb45e75c252ebf2bf51188c0a0 (diff)
common: Add option for global nixpkgs config.
This should make creating ~/.nixpkgs/config.nix obsolete and we can
solely decide whether we actually want these overrides by modifying
NIX_PATH alone.

The option isn't enabled by default, because this doesn't work if for
example /etc/nixos/configuration.nix is not readable by the user using
nix-env or importing <nixpkgs> by other means.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'modules/profiles')
-rw-r--r--modules/profiles/common.nix33
1 files changed, 26 insertions, 7 deletions
diff --git a/modules/profiles/common.nix b/modules/profiles/common.nix
index c941d636..0be2be96 100644
--- a/modules/profiles/common.nix
+++ b/modules/profiles/common.nix
@@ -1,4 +1,4 @@
-{ config, lib, ... }:
+{ config, pkgs, lib, ... }:
 
 with lib;
 
@@ -15,6 +15,17 @@ with lib;
       '';
     };
 
+    enableGlobalNixpkgsConfig = mkOption {
+      type = types.bool;
+      default = false;
+      description = ''
+        Enabling this links <literal>nixos-config</literal> to be used by
+        <literal>nixpkgs-config</literal>, which essentially means that
+        attributes defined in <option>nixpkgs.config</option> are also in effect
+        for user environments.
+      '';
+    };
+
     channelName = mkOption {
       type = types.str;
       default = "vuizvui";
@@ -46,13 +57,21 @@ with lib;
     ];
 
     nix.nixPath = let
+      nixpkgs = import ../../nixpkgs-path.nix;
       rootChannelsPath = "/nix/var/nix/profiles/per-user/root/channels";
       channelPath = "${rootChannelsPath}/${config.vuizvui.channelName}";
-    in mkIf config.vuizvui.modifyNixPath (mkOverride 90 [
-      "vuizvui=${channelPath}"
-      "nixpkgs=${channelPath}/nixpkgs"
-      "nixos-config=/etc/nixos/configuration.nix"
-      rootChannelsPath
-    ]);
+      nixosConfig = "/etc/nixos/configuration.nix";
+      nixpkgsConfig = "nixpkgs-config=${pkgs.writeText "nixpkgs-config.nix" ''
+        (import ${nixpkgs}/nixos/lib/eval-config.nix {
+          modules = [ ${nixosConfig} ];
+        }).config.nixpkgs.config
+      ''}";
+      nixPath = [
+        "vuizvui=${channelPath}"
+        "nixpkgs=${channelPath}/nixpkgs"
+        "nixos-config=${nixosConfig}"
+        rootChannelsPath
+      ] ++ optional config.vuizvui.enableGlobalNixpkgsConfig nixpkgsConfig;
+    in mkIf config.vuizvui.modifyNixPath (mkOverride 90 nixPath);
   };
 }