aboutsummaryrefslogtreecommitdiff
path: root/flakes/lib/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'flakes/lib/flake.nix')
-rw-r--r--flakes/lib/flake.nix28
1 files changed, 28 insertions, 0 deletions
diff --git a/flakes/lib/flake.nix b/flakes/lib/flake.nix
new file mode 100644
index 0000000..8faa136
--- /dev/null
+++ b/flakes/lib/flake.nix
@@ -0,0 +1,28 @@
1{
2 inputs.nixpkgs.url = "github:NixOS/nixpkgs";
3
4 description = "Useful libs";
5 outputs = { self, nixpkgs }: {
6 lib = rec {
7 computeNarHash = path:
8 let pkgs = import nixpkgs {};
9 in
10 builtins.readFile (pkgs.runCommand "narHash" {
11 buildInputs = [ pkgs.nix ];
12 } "echo -n $(nix hash-path ${path}) > $out");
13
14 withNarKeyCompat = flakeCompat: path: moduleAttrs:
15 let module = (flakeCompat path).${moduleAttrs};
16 narHash = computeNarHash path;
17 in if builtins.isFunction module
18 then args@{ config, lib, pkgs, ... }: (module args // { key = narHash; })
19 else module // { key = narHash; };
20
21 withNarKey = dep: moduleAttrs:
22 let module = dep.${moduleAttrs};
23 in if builtins.isFunction module
24 then args@{ config, lib, pkgs, ... }: (module args // { key = dep.narHash; })
25 else module // { key = dep.narHash; };
26 };
27 };
28}