diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-10-15 17:52:10 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-10-15 18:16:29 +0200 |
commit | 7d38060a0da2698052e84a0cfee422d409a38187 (patch) | |
tree | b81347894cd8c8468e24d2262f4e226a48598575 /flake.nix | |
parent | 0bc8f1669d542ef65fbfa80ea3728f4dd36d63f2 (diff) |
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.
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -13,8 +13,10 @@ systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); + # Memoize nixpkgs for different platforms for efficiency. - nixpkgsFor = nixpkgs.lib.genAttrs systems (system: + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; @@ -427,19 +429,19 @@ }; - checks = { - binaryTarball = self.hydraJobs.binaryTarball.x86_64-linux; - perlBindings = self.hydraJobs.perlBindings.x86_64-linux; - }; + checks = forAllSystems (system: { + binaryTarball = self.hydraJobs.binaryTarball.${system}; + perlBindings = self.hydraJobs.perlBindings.${system}; + }); - packages = { - inherit (nixpkgsFor.x86_64-linux) nix; - }; + packages = forAllSystems (system: { + inherit (nixpkgsFor.${system}) nix; + }); - defaultPackage = self.packages.nix; + defaultPackage = forAllSystems (system: self.packages.${system}.nix); - devShell = - with nixpkgsFor.x86_64-linux; + devShell = forAllSystems (system: + with nixpkgsFor.${system}; with commonDeps pkgs; stdenv.mkDerivation { @@ -461,7 +463,7 @@ PATH=$prefix/bin:$PATH unset PYTHONPATH ''; - }; + }); }; } |