mirror of
https://github.com/NixOS/nix
synced 2025-07-07 14:21:48 +02:00
Support non-x86_64-linux system types in flakes
A command like $ nix run nixpkgs#hello will now build the attribute 'packages.${system}.hello' rather than 'packages.hello'. Note that this does mean that the flake needs to export an attribute for every system type it supports, and you can't build on unsupported systems. So 'packages' typically looks like this: packages = nixpkgs.lib.genAttrs ["x86_64-linux" "i686-linux"] (system: { hello = ...; }); The 'checks', 'defaultPackage', 'devShell', 'apps' and 'defaultApp' outputs similarly are now attrsets that map system types to derivations/apps. 'nix flake check' checks that the derivations for all platforms evaluate correctly, but only builds the derivations in 'checks.${system}'. Fixes #2861. (That issue also talks about access to ~/.config/nixpkgs and --arg, but I think it's reasonable to say that flakes shouldn't support those.) The alternative to attribute selection is to pass the system type as an argument to the flake's 'outputs' function, e.g. 'outputs = { self, nixpkgs, system }: ...'. However, that approach would be at odds with hermetic evaluation and make it impossible to enumerate the packages provided by a flake.
This commit is contained in:
parent
0bc8f1669d
commit
7d38060a0d
7 changed files with 109 additions and 61 deletions
|
@ -34,8 +34,8 @@ cat > $flake1Dir/flake.nix <<EOF
|
|||
description = "Bla bla";
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages.foo = import ./simple.nix;
|
||||
defaultPackage = packages.foo;
|
||||
packages.$system.foo = import ./simple.nix;
|
||||
defaultPackage.$system = packages.$system.foo;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
@ -51,7 +51,7 @@ cat > $flake2Dir/flake.nix <<EOF
|
|||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake1 }: rec {
|
||||
packages.bar = flake1.packages.foo;
|
||||
packages.$system.bar = flake1.packages.$system.foo;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
@ -66,10 +66,10 @@ cat > $flake3Dir/flake.nix <<EOF
|
|||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake2 }: rec {
|
||||
packages.xyzzy = flake2.packages.bar;
|
||||
packages.$system.xyzzy = flake2.packages.$system.bar;
|
||||
|
||||
checks = {
|
||||
xyzzy = packages.xyzzy;
|
||||
xyzzy = packages.$system.xyzzy;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -182,8 +182,8 @@ cat > $flake3Dir/flake.nix <<EOF
|
|||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake1, flake2 }: rec {
|
||||
packages.xyzzy = flake2.packages.bar;
|
||||
packages."sth sth" = flake1.packages.foo;
|
||||
packages.$system.xyzzy = flake2.packages.$system.bar;
|
||||
packages.$system."sth sth" = flake1.packages.$system.foo;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
@ -242,9 +242,9 @@ cat > $flake3Dir/flake.nix <<EOF
|
|||
description = "Fnord";
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages.xyzzy = inputs.flake2.packages.bar;
|
||||
packages.sth = inputs.flake1.packages.foo;
|
||||
packages.fnord =
|
||||
packages.$system.xyzzy = inputs.flake2.packages.$system.bar;
|
||||
packages.$system.sth = inputs.flake1.packages.$system.foo;
|
||||
packages.$system.fnord =
|
||||
with import ./config.nix;
|
||||
mkDerivation {
|
||||
inherit system;
|
||||
|
@ -307,8 +307,8 @@ cat > $flake3Dir/flake.nix <<EOF
|
|||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake1, flake2, nonFlake }: rec {
|
||||
packages.sth = flake1.packages.foo;
|
||||
packages.fnord =
|
||||
packages.$system.sth = flake1.packages.$system.foo;
|
||||
packages.$system.fnord =
|
||||
with import ./config.nix;
|
||||
mkDerivation {
|
||||
inherit system;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue