-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.nix
More file actions
65 lines (59 loc) · 1.86 KB
/
lib.nix
File metadata and controls
65 lines (59 loc) · 1.86 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
...
}:
let
# This function expects this repository to be at ~/dotfiles
mkDotfilesSymlink =
config: pathFromHome:
config.hm-gep.lib.file.mkOutOfStoreSymlink "${config.hm-gep.home.homeDirectory}/dotfiles/${pathFromHome}";
# https://github.com/NixOS/nixpkgs/issues/254265
removeLicense =
pkgs: pkg:
pkgs.symlinkJoin {
name = "${pkg.name}-no-license";
paths = [ pkg ];
postBuild = ''
rm -f $out/LICENSE
'';
};
nixpkgsHash =
self:
let
lib = self.inputs.nixpkgs.lib;
relevantInputs = lib.filterAttrs (name: value: lib.hasPrefix "nixpkgs" name) self.inputs;
inputHashes = lib.mapAttrsToList (name: value: value.narHash) relevantInputs;
inputsHash = builtins.hashString "sha256" (lib.concatStrings inputHashes);
inputsHashShort = lib.substring 0 4 inputsHash;
in
"${self.inputs.nixpkgs.narHash}-${inputsHashShort}";
doCacheDerivations = true;
cacheDerivation = cacheKey: derivation: builtins.trace "cache=${cacheKey}" derivation;
cachePackage =
self: package: cacheDerivation "nixpkgs-package-${package.name}-${nixpkgsHash self}" package;
maybeCacheDerivation =
cacheKey: derivation:
if doCacheDerivations then cacheDerivation cacheKey derivation else derivation;
maybeCachePackage =
self: package: if doCacheDerivations then cachePackage self package else package;
maybeCachePackages =
self: packages: if doCacheDerivations then map (maybeCachePackage self) packages else packages;
maybeCachePackageOverlay =
self: packageName: final: prev:
if doCacheDerivations then
{
"${packageName}" = cachePackage self (prev."${packageName}");
}
else
{ };
in
{
inherit
mkDotfilesSymlink
removeLicense
nixpkgsHash
maybeCacheDerivation
maybeCachePackage
maybeCachePackages
maybeCachePackageOverlay
;
}