diff --git a/index.html b/index.html index 9bcc576..9f8fce0 100644 --- a/index.html +++ b/index.html @@ -215,15 +215,10 @@
  • 10.5. Build/runtime environments -
  • -
  • 10.6. Special situations
  • -
  • 10.7. An (old-style) Nix shell with access to a flake
  • +
  • 10.6. An (old-style) Nix shell with access to a flake
  • @@ -4982,11 +4977,11 @@ hello-nix inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; - hello-nix = { - url = "git+https://codeberg.org/mhwombat/hello-nix"; - flake = false; - }; - }; + hello-nix = { + url = "git+https://codeberg.org/mhwombat/hello-nix"; + flake = false; + }; + }; outputs = { self, nixpkgs, flake-utils, hello-nix }: flake-utils.lib.eachDefaultSystem (system: @@ -4994,8 +4989,8 @@ hello-nix pkgs = import nixpkgs { inherit system; }; - helloNix = import hello-nix { inherit pkgs; }; - in + helloNix = import hello-nix { inherit pkgs; }; + in { packages = rec { hello = pkgs.stdenv.mkDerivation rec { @@ -5008,13 +5003,13 @@ hello-nix buildPhase = ":"; installPhase = - '' - mkdir -p $out/bin - cp $src/hello-again $out/bin - chmod +x $out/bin/hello-again + '' + mkdir -p $out/bin + cp $src/hello-again $out/bin + chmod +x $out/bin/hello-again - # modify the hello-again script so it can find hello-nix - HELLO=$(type -p hello-nix) + # modify the hello-again script so it can find hello-nix + HELLO=$(type -p hello-nix) sed "s_hello-nix_"$HELLO"_" --in-place $out/bin/hello-again ''; @@ -5035,8 +5030,15 @@ hello-nix
    -

    We already covered how to add a non-flake input to a flake and build it in Section 10.4.6, “Access a non-flake package (not in nixpkgs)”; -Lines 5-8 and 17 were explained in Section 10.4.6, “Access a non-flake package (not in nixpkgs)”.

    +

    Lines 5-8 and 17 were explained in Section 10.4.6, “Access a non-flake package (not in nixpkgs)”. +As expected, we need to add helloNix as a build input, which we do in line 36. +That does make it available at build and runtime, but it doesn’t put it on the path, +so our hello-again script won’t be able to find it.

    +
    +
    +

    There are various ways to deal with this problem. +In this case we simply edited the script as we install it, +by specifying the full path to hello-nix.

    Here’s a demonstration using the shell.

    @@ -5044,46 +5046,19 @@ Lines 5-8 and 17 were explained in Section 10.
    $ hello-nix # this will fail
    -bash: line 34: hello-nix: command not found
    +bash: line 40: hello-nix: command not found
     $ nix develop
    -building '/nix/store/q7fkc1pi5bv5nm26iaqqxps8av935cfi-hello-again-env.drv'...
     $ hello-nix
     Hello from your nix package!
    -
    -
    If the nix derivation requires nixpkgs
    -
    -

    In this case, we need to write the derivation ourselves. -We can use default.nix as a model. -Line 15 should be replaced with:

    -
    -
    -
    -
           helloNix = pkgs.stdenv.mkDerivation {
    -         name = "hello-nix";
    -         src = hello-nix;
    -         installPhase =
    -           ''
    -             mkdir -p $out/bin
    -             cp $src/hello-nix $out/bin/hello-nix
    -             chmod +x $out/bin/hello-nix
    -           '';
    -       };
    -
    -

    Unresolved directive in recipes/build/main.adoc - include::non-flake/main-generated.adoc[leveloffset=+1]

    -
    -

    10.6. Special situations

    - -
    -
    -

    10.7. An (old-style) Nix shell with access to a flake

    +

    10.6. An (old-style) Nix shell with access to a flake

    If you are maintaining legacy code, you may need to provide access to a flake in a nix-shell. @@ -5141,7 +5116,7 @@ Hello from your flake!

    diff --git a/source/recipes/build/nix-non-flake/tempwork/flake.lock b/source/recipes/build/nix-non-flake/tempwork/flake.lock index 2a40054..4ae4a66 100644 --- a/source/recipes/build/nix-non-flake/tempwork/flake.lock +++ b/source/recipes/build/nix-non-flake/tempwork/flake.lock @@ -36,11 +36,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1757771770, - "narHash": "sha256-/JghEYWMoO5kV+CQREWs0W+z2g27fHFAkRIP3TQZ5dI=", + "lastModified": 1757775813, + "narHash": "sha256-mHYalJeeuYTtJNPijlm4IqmxslIB+DTz/wQvz2EB/S4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5f7451255f69dc631d3697f274406e936584d876", + "rev": "1fb62b80407f458b29ba8168c11095858a250687", "type": "github" }, "original": { diff --git a/source/recipes/main.adoc b/source/recipes/main.adoc index 7f72f9c..65c6cc5 100644 --- a/source/recipes/main.adoc +++ b/source/recipes/main.adoc @@ -22,6 +22,4 @@ include::devshell/main.adoc[leveloffset=+1] include::build/main.adoc[leveloffset=+1] -== Special situations - include::nix-shell/main-generated.adoc[leveloffset=+1]