This commit is contained in:
Amy de Buitléir 2025-09-15 17:31:13 +01:00
parent 77354ff20c
commit bd082ef03a
7 changed files with 42 additions and 66 deletions

View file

@ -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`.

View file

@ -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;
};
}
);
}

View file

@ -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

View file

@ -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.

View file

@ -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": {

View 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 ];
};
};
}
);
}