Created
May 15, 2023 08:13
-
-
Save thufschmitt/b8936f2184c68f4b7c3ea0fe294b64e2 to your computer and use it in GitHub Desktop.
Discard references in 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
let p = import <nixpkgs> {}; in | |
let | |
discardReferences = path: | |
let | |
# We want to use a different nixpkgs here to make sure that the `noref` | |
# version won't accidentally share some build-time references with the | |
# original one | |
p2 = (builtins.getFlake "github:nixos/nixpkgs/nixos-unstable").legacyPackages.${builtins.currentSystem}; | |
mangledPath = p2.runCommandNoCC "${path.name}.tar.gz" {} '' | |
cd ${path} | |
tar -cz . > $out | |
''; | |
mangledPathNoRef = builtins.seq | |
(builtins.pathExists mangledPath) | |
(/${builtins.unsafeDiscardStringContext mangledPath}); | |
pathNoRef = p2.runCommandNoCC "${path.name}-noref" { passthru.original = path; } '' | |
mkdir -p $out | |
cd $out | |
tar -xzf ${mangledPathNoRef} | |
''; | |
in pathNoRef; | |
in discardReferences p.hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment