mermet: croc: polish
[sourcephile-nix.git] / shell / modules / tools / package-management / nix.nix
index 88c0da6fbeadacb1013cde1c4298271f1e1e2605..041e0d2abbd27ce2351bc774401f36fab9ef8dcd 100644 (file)
@@ -1,8 +1,11 @@
-{ config, lib, pkgs, ... }:
+{ pkgs, lib, config, ... }:
 let cfg = config.nix;
     inherit (lib) types;
-    /* Alternative which does not need to re-export envvars when called via sudo.
-       But this is maybe more clear to just (re-)export envvars.
+    # Alternative which does not need to re-export envvars when called via sudo.
+    # But this is maybe more clear to just (re-)export envvars.
+    # And anyway, using NIX_CONF_DIR=${cfg.nixConf} directly does not work,
+    # maybe because of filesystem restriction access set by nix, I don't know.
+    /*
     nix = pkgs.writeShellScriptBin "nix" ''
       NIX_CONF_DIR=${cfg.nixConf} \
       NIX_SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" \
@@ -26,10 +29,13 @@ in
     };
   };
   config = lib.mkIf cfg.enable {
-    #shell.buildInputs = [ nix ];
+    #nix-shell.buildInputs = [ nix ];
     nix-shell.shellHook = ''
       # nix
-      export NIX_CONF_DIR=${cfg.nixConf}
+      # NOTE: linking NIX_CONF_DIR directly to ${cfg.nixConf} does not work.
+      mkdir -p "$PWD"/.config/nix
+      ln -fns ${cfg.nixConf} "$PWD"/.config/nix/nix.conf
+      export NIX_CONF_DIR="$PWD"/.config/nix
       export NIX_SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
       export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
     '';