Last active
September 29, 2023 07:03
-
-
Save ruuda/c17509f6684e6e01bc9017a39d86addf to your computer and use it in GitHub Desktop.
Monadic Nix Example
This file contains hidden or 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
{ pkgs ? | |
import (fetchTarball { | |
url = "https://github.com/NixOS/nixpkgs/archive/13b2903169f18ac98ed737effb36dabc48051978.tar.gz"; | |
sha256 = "1ql9ychp7w7ciqyb7am22b9hrlsz2sppgjflgr0ffw92gvwi3m64"; | |
}) {} | |
}: | |
with pkgs; | |
let | |
outer = stdenv.mkDerivation { | |
name = "outer"; | |
phases = ["buildPhase"]; | |
buildPhase = '' | |
mkdir -p $out | |
cat << EOF > $out/default.nix | |
with (import (fetchTarball { | |
url = "https://github.com/NixOS/nixpkgs/archive/13b2903169f18ac98ed737effb36dabc48051978.tar.gz"; | |
sha256 = "1ql9ychp7w7ciqyb7am22b9hrlsz2sppgjflgr0ffw92gvwi3m64"; | |
}) {} | |
); | |
stdenv.mkDerivation { | |
name = "inner"; | |
phases = ["buildPhase"]; | |
# Is this bad? Now the store path depends on when you first ran nix-build! | |
# Note that this is not a non-reproducible build of "inner", it is an issue | |
# with "outer". | |
buildPhase = "mkdir -p \$out; echo 'hi from inner at $(date)' > \$out/hi.txt"; | |
} | |
EOF | |
''; | |
}; | |
in | |
import outer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment