summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-05-04 09:27:40 +0200
committerAlan Pearce2024-05-18 12:17:12 +0200
commit782e0000196146183ee4a7e91e60424c24652d2f (patch)
treeb21a2690ed3ecbd7085f653d1ba53a1236708a58
parent72e7e31cefd86fba84924c9b579020a4b733426c (diff)
downloadnixfiles-782e0000196146183ee4a7e91e60424c24652d2f.tar.lz
nixfiles-782e0000196146183ee4a7e91e60424c24652d2f.tar.zst
nixfiles-782e0000196146183ee4a7e91e60424c24652d2f.zip
nix: set nix.nixPath
-rw-r--r--lib/default.nix21
-rw-r--r--shell.nix18
-rw-r--r--system/settings/configuration/nix.nix1
-rw-r--r--system/settings/pin.nix8
4 files changed, 32 insertions, 16 deletions
diff --git a/lib/default.nix b/lib/default.nix
new file mode 100644
index 00000000..93f64059
--- /dev/null
+++ b/lib/default.nix
@@ -0,0 +1,21 @@
+{ pkgs }:
+with builtins;
+let
+  inherit (pkgs) lib;
+in
+rec {
+  importPathStore = p: "${append ../. "/${p}"}";
+
+  mkPathable = s:
+    if
+      s.type == "local"
+    then
+      lib.path.append ../. s.outPath
+    else
+      toString s.outPath
+  ;
+
+  mkNixPath = sources: lib.attrsets.mapAttrsToList
+    (k: v: "${k}=${mkPathable v}")
+    (removeAttrs sources [ "__functor" ]);
+}
diff --git a/shell.nix b/shell.nix
index 9167cb7e..81938c3f 100644
--- a/shell.nix
+++ b/shell.nix
@@ -2,26 +2,12 @@ with builtins;
 
 let
   sources = import ./nix/sources.nix;
-  sourcesJSON = fromJSON (readFile ./nix/sources.json);
 
   nixpkgs = sources.nixpkgs;
   pkgs = import nixpkgs { };
-  inherit (pkgs.lib) path attrsets;
+  lib = import ./lib { inherit pkgs; };
 
-  mkPathable = v: toString (
-    if
-      path.subpath.isValid v
-    then
-      path.append ./. v
-    else
-      v
-  );
-
-  nixPath = concatStringsSep ":" (
-    attrsets.mapAttrsToList
-      (k: v: "${k}=${mkPathable (getAttr "outPath" v)}")
-      (intersectAttrs sourcesJSON sources)
-  );
+  nixPath = concatStringsSep ":" (lib.mkNixPath sources);
 in
 pkgs.mkShell
 {
diff --git a/system/settings/configuration/nix.nix b/system/settings/configuration/nix.nix
index 57c7cedf..97cd7aeb 100644
--- a/system/settings/configuration/nix.nix
+++ b/system/settings/configuration/nix.nix
@@ -3,6 +3,7 @@
 , pkgs
 , ...
 }: {
+  imports = [ ../pin.nix ];
   nix = {
     settings = {
       cores = lib.mkDefault 0;
diff --git a/system/settings/pin.nix b/system/settings/pin.nix
new file mode 100644
index 00000000..e282cf66
--- /dev/null
+++ b/system/settings/pin.nix
@@ -0,0 +1,8 @@
+{ pkgs, ... }:
+let
+  lib = import ../../lib { inherit pkgs; };
+  sources = import ../../nix/sources.nix;
+in
+{
+  nix.nixPath = lib.mkNixPath sources;
+}