Last active
July 13, 2022 19:40
-
-
Save rrbutani/474ec08b6b5f3389c39ed7fd3ff4dc13 to your computer and use it in GitHub Desktop.
Lazy Flake Inputs, with the `cache-flake-inputs` flake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(see flake.nix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nodes": { | |
"cfi": { | |
"inputs": { | |
"cache-flake-inputs-global-override": [ | |
"cfi-override" | |
], | |
"flu": "flu", | |
"nixpkgs": "nixpkgs" | |
}, | |
"locked": { | |
"lastModified": 1657740012, | |
"narHash": "sha256-l6aTMD1zkxRxYwka+eqQZ66YOmJ3xGUAtRTptzQEpFw=", | |
"owner": "rrbutani", | |
"repo": "cache-flake-inputs", | |
"rev": "1213940c8196ecf569ccc80bc75b1028583c5678", | |
"type": "github" | |
}, | |
"original": { | |
"owner": "rrbutani", | |
"repo": "cache-flake-inputs", | |
"type": "github" | |
} | |
}, | |
"cfi-override": { | |
"locked": { | |
"lastModified": 1657739253, | |
"narHash": "sha256-L9eyTL7njtPBUYmZRYFKCzQFDgua9U9oE7UwCzjZfl8=", | |
"owner": "boolean-option", | |
"repo": "true", | |
"rev": "6ecb49143ca31b140a5273f1575746ba93c3f698", | |
"type": "github" | |
}, | |
"original": { | |
"owner": "boolean-option", | |
"repo": "true", | |
"type": "github" | |
} | |
}, | |
"flu": { | |
"locked": { | |
"lastModified": 1656928814, | |
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", | |
"owner": "numtide", | |
"repo": "flake-utils", | |
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", | |
"type": "github" | |
}, | |
"original": { | |
"owner": "numtide", | |
"repo": "flake-utils", | |
"type": "github" | |
} | |
}, | |
"flu_2": { | |
"locked": { | |
"lastModified": 1656928814, | |
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", | |
"owner": "numtide", | |
"repo": "flake-utils", | |
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", | |
"type": "github" | |
}, | |
"original": { | |
"owner": "numtide", | |
"repo": "flake-utils", | |
"type": "github" | |
} | |
}, | |
"llvm": { | |
"flake": false, | |
"locked": { | |
"lastModified": 1655916384, | |
"narHash": "sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE=", | |
"owner": "llvm", | |
"repo": "llvm-project", | |
"rev": "f28c006a5895fc0e329fe15fead81e37457cb1d1", | |
"type": "github" | |
}, | |
"original": { | |
"owner": "llvm", | |
"ref": "llvmorg-14.0.6", | |
"repo": "llvm-project", | |
"type": "github" | |
} | |
}, | |
"nixpkgs": { | |
"locked": { | |
"lastModified": 1653936696, | |
"narHash": "sha256-M6bJShji9AIDZ7Kh7CPwPBPb/T7RiVev2PAcOi4fxDQ=", | |
"owner": "nixOS", | |
"repo": "nixpkgs", | |
"rev": "ce6aa13369b667ac2542593170993504932eb836", | |
"type": "github" | |
}, | |
"original": { | |
"owner": "nixOS", | |
"ref": "22.05", | |
"repo": "nixpkgs", | |
"type": "github" | |
} | |
}, | |
"nixpkgs_2": { | |
"locked": { | |
"lastModified": 1653936696, | |
"narHash": "sha256-M6bJShji9AIDZ7Kh7CPwPBPb/T7RiVev2PAcOi4fxDQ=", | |
"owner": "nixOS", | |
"repo": "nixpkgs", | |
"rev": "ce6aa13369b667ac2542593170993504932eb836", | |
"type": "github" | |
}, | |
"original": { | |
"owner": "nixOS", | |
"ref": "22.05", | |
"repo": "nixpkgs", | |
"type": "github" | |
} | |
}, | |
"root": { | |
"inputs": { | |
"cfi": "cfi", | |
"cfi-override": "cfi-override", | |
"flu": "flu_2", | |
"llvm": "llvm", | |
"nixpkgs": "nixpkgs_2" | |
} | |
} | |
}, | |
"root": "root", | |
"version": 7 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
nixConfig = { | |
# A remote cache that you provide. | |
extra-substituters = [ | |
"https://rrbutani.cachix.org" | |
]; | |
extra-trusted-public-keys = [ | |
"rrbutani.cachix.org-1:FUpcK9RyZjjdOm8qherJl9+wfTGf6ptANvH6LZF63Ro=" | |
]; | |
}; | |
inputs = { | |
# A large unwieldy flake input (an example). | |
llvm = { | |
url = github:llvm/llvm-project?ref=llvmorg-14.0.6; | |
flake = false; | |
}; | |
flu.url = github:numtide/flake-utils; | |
nixpkgs.url = github:nixOS/nixpkgs/22.05; | |
cfi-override.url = github:boolean-option/true; | |
cfi = { | |
url = github:rrbutani/cache-flake-inputs; | |
# You can set `cfi-override.url` (above) to `github:boolean-option/false` | |
# to disable `cacheInputs`. | |
# | |
# This is useful for changing the behavior of your _transitive_ flake dependencies. | |
inputs.cache-flake-inputs-global-override.follows = "cfi-override"; | |
}; | |
}; | |
outputs = inputs@{ flu, cfi, nixpkgs, ... }: with flu.lib; eachDefaultSystem (sys: let | |
knownCachedNarHashes = { | |
# Keys should match the names of your flake inputs. | |
"llvm" = { | |
# Hashes should match what's in your `flake.lock`. | |
"sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE=" = true; | |
}; | |
}; | |
np = import nixpkgs { system = sys; }; | |
inputs' = cfi.lib.${sys}.cacheInputs { | |
inherit inputs knownCachedNarHashes; | |
lockFile = ./flake.lock; | |
# This tells `cfi` to assume that we can indeed use substituters to get the | |
# things `knownCachedNarHashes` says we can. | |
# | |
# If this is set to `false`, `cfi` will effectively do nothing; derivations | |
# in `inputs'` will be equivalent to the ones in `inputs` and flake inputs | |
# will be fetched eagerly during evaluation. | |
useSubstituters = true; | |
# We already have a `nixpkgs` instance so pass it along. | |
# | |
# This is optional; if omitted, `cfi` will use it's own `nixpkgs` flake | |
# input — which you can override with `inputs.cfi.inputs.nixpkgs.follows`). | |
nixpkgs = np; | |
}; | |
pkgC = src: np.stdenvNoCC.mkDerivation { | |
name = "example"; | |
src = src; | |
unpackPhase = "true"; | |
installPhase = '' | |
cat $src/libunwind/CMakeLists.txt | grep PACKAGE_VERSION | cut -d' ' -f4- | cut -d')' -f1 | head -1 > $out | |
''; | |
}; | |
# Both `pkgA` and `pkgB` are in the substituter listed at the top of this flake. | |
# Building `pkgA` will require fetching LLVM. | |
pkgA = pkgC inputs.llvm; | |
# Building `pkgB` will not. | |
pkgB = pkgC inputs'.llvm; | |
in { | |
packages = { | |
default = pkgB; | |
inherit pkgA pkgB; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment