aboutsummaryrefslogtreecommitdiff
path: root/flakes/lib/flake.nix
blob: 8faa136898ce51107e1ab6156f96a1c3b1cf40de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs";

  description = "Useful libs";
  outputs = { self, nixpkgs }: {
    lib = rec {
      computeNarHash = path:
        let pkgs = import nixpkgs {};
        in
          builtins.readFile (pkgs.runCommand "narHash" {
            buildInputs = [ pkgs.nix ];
          } "echo -n $(nix hash-path ${path}) > $out");

      withNarKeyCompat = flakeCompat: path: moduleAttrs:
        let module = (flakeCompat path).${moduleAttrs};
            narHash = computeNarHash path;
        in if builtins.isFunction module
          then args@{ config, lib, pkgs, ... }: (module args // { key = narHash; })
          else module // { key = narHash; };

      withNarKey = dep: moduleAttrs:
        let module = dep.${moduleAttrs};
        in if builtins.isFunction module
          then args@{ config, lib, pkgs, ... }: (module args // { key = dep.narHash; })
          else module // { key = dep.narHash; };
    };
  };
}