Skip to content

Commit

Permalink
Add nix-all-output-paths
Browse files Browse the repository at this point in the history
This implements the `fallback-paths.nix` format in NixOS
  • Loading branch information
roberth committed Sep 23, 2024
1 parent ca3fc16 commit 7bd3f3b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@
default = self.packages.${system}.nix-ng;
nix-internal-api-docs = nixpkgsFor.${system}.native.nixComponents.nix-internal-api-docs;
nix-external-api-docs = nixpkgsFor.${system}.native.nixComponents.nix-external-api-docs;
nix-all-output-paths = nixpkgsFor.${system}.native.callPackage ./packaging/nix-all-output-paths.nix {
packages =
lib.mapAttrs (system: packages: packages.nix) self.packages;
};
}
# We need to flatten recursive attribute sets of derivations to pass `flake check`.
// flatMapAttrs
Expand Down
48 changes: 48 additions & 0 deletions packaging/nix-all-output-paths.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ lib, formats, nix, packages, stdenv, ... }:

let
randomPick = packages."x86_64-linux";
in
stdenv.mkDerivation {
version = randomPick.version;
pname = "nix-all-output-paths";
passAsFile = [ "content" ];
nativeBuildInputs = [ nix ];
json = (formats.json {}).generate "all-output-paths.json" (lib.mapAttrs (name: pkg: "${lib.getBin pkg}") packages);
nix = ''
{
${
lib.concatStringsSep "\n " (
lib.mapAttrsToList
(name: pkg: "${lib.strings.escapeNixIdentifier name} = ${lib.strings.escapeNixString "${lib.getBin pkg}"};")
packages
)
}
}
'';
buildCommand = ''
mkdir -p $out
cp $json $out/all-output-paths.json
echo "$nix" > $out/all-output-paths.nix
mkdir -p $out/nix-support
{
echo "file all-output-paths $out/all-output-paths.json"
echo "file all-output-paths-nix-deprecated $out/all-output-paths.nix"
} >> $out/nix-support/hydra-build-products
r=$(nix-instantiate --store dummy:// --expr --eval --json \
'builtins.fromJSON (builtins.readFile '$out'/all-output-paths.json) == import '$out'/all-output-paths.nix')
if ! [[ $r == "true" ]]; then
echo "The generated Nix file does not match the JSON file"
echo "Nix file: $out/all-output-paths.nix"
cat -n $out/all-output-paths.nix
echo "JSON file: $out/all-output-paths.json"
cat -n $out/all-output-paths.json
exit 1
fi
'';
meta = {
description = "A lookup file that gives a store path containing the Nix package manager for all supported system types";
};
}

0 comments on commit 7bd3f3b

Please sign in to comment.