]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - flakes/lib/flake.nix
Add filesWatcher flake
[perso/Immae/Config/Nix.git] / flakes / lib / flake.nix
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 }