Open aakropotkin opened 2 years ago
A second useful example that is backwards compatible with Nix versions < 2.7:
{
description = "My DWM Config";
inputs.utils.url = github:numtide/flake-utils;
inputs.utils.inputs.nixpkgs.follows = "nixpkgs";
outputs = { self, nixpkgs, utils }:
let defaultSystemsMap = utils.lib.eachSystemMap utils.lib.defaultSystems;
in {
packages = defaultSystemsMap ( system:
let pkgsFor = import nixpkgs { inherit system; };
in rec {
ak-dwm = pkgsFor.stdenv.mkDerivation {
pname = "ak-dwm";
version = "0.0.1";
src = self;
depsTargetTarget = with pkgsFor.xorg; [
libX11 libXinerama libXft
];
prePatch = ''
sed -i "s,/usr/local,$out," config.mk
'';
};
default = ak-dwm;
} );
} // ( if ( ( builtins.compareVersions __nixVersion "2.7.0" ) <= 0 )
then {
defaultPackage =
defaultSystemsMap ( system: self.packages.${system}.default );
} else {} );
}
This passes all of the following:
nix shell github:NixOS/nix/2.7-maintanence#nix -c nix flake check --impure;
nix shell github:NixOS/nix/2.6-maintanence#nix -c nix flake check --impure;
nix shell github:NixOS/nix/2.7-maintanence#nix -c nix build --impure;
nix shell github:NixOS/nix/2.6-maintanence#nix -c nix build --impure;
Notably it avoids depreciation warnings when run on 2.7 or later which would normally appear for nix flake check
in 2.7 or later.
Thanks, I think this will be useful for people who search. (edited your messages to add highlighting on the nix code)
Hey I'm not here to really gripe about anything missing, but more to highlight how recent changes to the flake spec in Nix 2.7.0 make
eachSystemMap
a really elegant function.If you agree I I'll PR some
README
updates to highlight the new patterns, since I think it'd be good to put it front and center.For context Nix 2.7.0 deprecates
defaultXXX.${system}
in favor ofpackages.${system}.default
making it easier to wrangle defining defaults. This snippet below is for a trivial project I have with a standard package installation. This flake makes it available tonix-command
, or it can be consumed inNixOS
/home-manager
as a module, or in legacynix
+nixpkgs
projects as an overlay.The boilerplate required previously to handle the
defautXXX
outputs used to be real ugly.