]>
Commit | Line | Data |
---|---|---|
27dd65fc IB |
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 | } |