mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2025-12-26 16:24:56 +08:00
temp
This commit is contained in:
parent
77354ff20c
commit
bd082ef03a
7 changed files with 42 additions and 66 deletions
|
|
@ -5249,7 +5249,8 @@ hello-flake
|
|||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Line 5 adds <code>hello-flake</code> as an input to this flake.
|
||||
<p>Line 5 adds <code>hello-flake</code> as an input to this flake,
|
||||
Line 8 allows the output function to reference <code>hello-flake</code>.
|
||||
As expected, we need to add <code>hello-flake</code> 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 <code>hello-again</code> script won’t be able to find it.</p>
|
||||
|
|
@ -5607,7 +5608,7 @@ Hello from your flake!</pre>
|
|||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2025-09-15 16:10:28 IST
|
||||
Last updated 2025-09-15 16:12:35 IST
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -55,3 +55,17 @@ $# rm temp.sh
|
|||
$# echo '$ '${executable}
|
||||
$# ${executable}
|
||||
....
|
||||
|
||||
== Flake outputs
|
||||
|
||||
You can find the outputs of a flake using the `nix flake show` command.
|
||||
|
||||
....
|
||||
$# echo '$ nix flake show --all-systems git+https://codeberg.org/mhwombat/hello-flake'
|
||||
$# nix flake show git+https://codeberg.org/mhwombat/hello-flake --quiet | sed -e 's/\x1b\[[0-9;]*m//g'
|
||||
....
|
||||
|
||||
Examining the output of this command,
|
||||
we see that this flake supports multiple architectures
|
||||
(aarch64-darwin, aarch64-linux, x86_64-darwin and x86_64-linux)
|
||||
and provides both a package and an app called `hello`.
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
hello-flake.url = "git+https://codeberg.org/mhwombat/hello-flake";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, hello-flake }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
packages = rec {
|
||||
hello = pkgs.stdenv.mkDerivation rec {
|
||||
name = "hello-again";
|
||||
|
||||
src = ./.;
|
||||
|
||||
unpackPhase = "true";
|
||||
|
||||
buildPhase = ":";
|
||||
|
||||
installPhase =
|
||||
''
|
||||
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-flake
|
||||
HELLO=$(type -p hello-flake)
|
||||
sed "s_hello-flake_"$HELLO"_" --in-place $out/bin/hello-again
|
||||
'';
|
||||
|
||||
|
||||
buildInputs = [ hello-flake.packages.${system}.hello ];
|
||||
};
|
||||
default = hello;
|
||||
};
|
||||
|
||||
apps = rec {
|
||||
hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; };
|
||||
default = hello;
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
echo "I'm a flake, and I'm running a command defined in a another flake."
|
||||
hello-flake
|
||||
|
|
@ -28,16 +28,7 @@ $# grep buildInputs flake.nix | sed 's/ //g; s/.*\[//; s/\].*//'
|
|||
Why is the first part `hello-flake` and the last part `hello`?
|
||||
The first part refers to the name we assigned in the input section of our flake,
|
||||
and the last part is the name of the package or app we want.
|
||||
|
||||
You can find the outputs of a flake using the `nix flake show` command.
|
||||
|
||||
....
|
||||
$# echo '$ nix flake show git+https://codeberg.org/mhwombat/hello-flake'
|
||||
$# nix flake show git+https://codeberg.org/mhwombat/hello-flake --quiet | sed -e 's/\x1b\[[0-9;]*m//g'
|
||||
....
|
||||
|
||||
Examining the output of this command,
|
||||
we see that this flake provides both a package and an app called `hello`.
|
||||
(See <<_flake_outputs>> for how to identify flake outputs.)
|
||||
|
||||
Here's a demonstration using the shell.
|
||||
|
||||
|
|
|
|||
|
|
@ -72,11 +72,11 @@
|
|||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1757945769,
|
||||
"narHash": "sha256-z/SdByTaDnEx4Zj0pyMwzY+uKxV/2TpQQ6ZKijKc2t0=",
|
||||
"lastModified": 1757952092,
|
||||
"narHash": "sha256-BcfTLFCU7elUJ2dwyt0iTjxsz/XLh+8ZygDcFwy6xPE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "62b2408b85dc46dab0b8ca4250471b9cb23425f0",
|
||||
"rev": "fd76dc9e7c68ac7c3941ba2af2bedcd79c5cf4ed",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
21
source/recipes/devshell/flake/tempwork/flake.nix
Normal file
21
source/recipes/devshell/flake/tempwork/flake.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
hello-flake.url = "git+https://codeberg.org/mhwombat/hello-flake";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, hello-flake }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
devShells = rec {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [ hello-flake.packages.${system}.hello ];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue