about summary refs log tree commit diff
path: root/modules/core/common.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2016-05-17 01:48:26 +0200
committeraszlig <aszlig@redmoonstudios.org>2016-05-17 01:48:26 +0200
commit0c7a53d2d0041c027f477fe89f8860ed5ae0b98d (patch)
tree2f5a34d021f4a7bff3956ae17088d7dadf911c6b /modules/core/common.nix
parentc3968ea04fe71b9e45432980c8c8326c7572eac6 (diff)
modules/profiles/*: Rename to modules/core/*
The name "profiles" really doesn't match what these modules are for.
Instead they define the very core of Vuizvui and its internal plumbing
and those options are available/enabled to all machines and modules.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'modules/core/common.nix')
-rw-r--r--modules/core/common.nix88
1 files changed, 88 insertions, 0 deletions
diff --git a/modules/core/common.nix b/modules/core/common.nix
new file mode 100644
index 00000000..dbaec7ed
--- /dev/null
+++ b/modules/core/common.nix
@@ -0,0 +1,88 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+{
+  options.vuizvui = {
+    modifyNixPath = mkOption {
+      type = types.bool;
+      default = true;
+      description = ''
+        Whether to modify NIX_PATH for vuizvui, so that &lt;nixpkgs&gt; points
+        to the path within the Nix channel instead of the
+        <literal>nixpkgs</literal> or <literal>nixos</literal> channel from the
+        root user.
+      '';
+    };
+
+    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";
+      description = ''
+        The channel name which is used to refer to <literal>vuizvui</literal>.
+      '';
+    };
+  };
+
+  config = let
+    nixpkgs = import ../../nixpkgs-path.nix;
+    system = config.nixpkgs.system;
+
+  in {
+    nixpkgs.config.packageOverrides = pkgs: {
+      # XXX: REAAAALLLY UGLY hack to force the Headcounter Hydra to rebuild GHC
+      # and all its packages and not use binary substitution.
+      haskellPackages = pkgs.haskellPackages.override {
+        ghc = pkgs.haskellPackages.ghc.overrideDerivation (const {
+          forceRebuild = true;
+        });
+      };
+
+      inherit (import ../../pkgs {
+        # We need to make sure to incorporate other package overrides,
+        # otherwise we are unable to override packages in vuizvui.*.
+        pkgs = pkgs // config.nixpkgs.config.packageOverrides pkgs;
+      }) vuizvui;
+    };
+
+    nix.binaryCachePublicKeys = [
+      "headcounter.org:/7YANMvnQnyvcVB6rgFTdb8p5LG1OTXaO+21CaOSBzg="
+    ];
+
+    environment.variables.NIXPKGS_CONFIG = let
+      nixpkgsCfg = toString (pkgs.writeText "nixpkgs-try-config.nix" ''
+        if (builtins.tryEval <nixpkgs-config>).success
+        then import <nixpkgs-config>
+        else {}
+      '');
+    in mkIf config.vuizvui.enableGlobalNixpkgsConfig (mkForce nixpkgsCfg);
+
+    nix.nixPath = let
+      rootChannelsPath = "/nix/var/nix/profiles/per-user/root/channels";
+      channelPath = "${rootChannelsPath}/${config.vuizvui.channelName}";
+      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);
+  };
+}