flake: simply packages with flattenTreeSystem

Based on https://github.com/numtide/flake-utils/pull/13.
This commit is contained in:
Timothy DeHerrera 2021-01-03 00:05:39 -07:00
parent 51deae41cc
commit 41e3de0eab
No known key found for this signature in database
GPG Key ID: 8985725DB5B0C122
2 changed files with 61 additions and 58 deletions

View File

@ -6,29 +6,32 @@
master.url = "nixpkgs/master"; master.url = "nixpkgs/master";
nixos.url = "nixpkgs/release-20.09"; nixos.url = "nixpkgs/release-20.09";
home.url = "github:nix-community/home-manager/release-20.09"; home.url = "github:nix-community/home-manager/release-20.09";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils/flatten-tree-system";
devshell.url = "github:numtide/devshell"; devshell.url = "github:numtide/devshell";
}; };
outputs = inputs@{ self, home, nixos, master, flake-utils, nur, devshell }: outputs = inputs@{ self, home, nixos, master, flake-utils, nur, devshell }:
let let
inherit (builtins) attrNames attrValues readDir elem pathExists filter; inherit (builtins) attrNames attrValues elem pathExists;
inherit (flake-utils.lib) eachDefaultSystem mkApp; inherit (flake-utils.lib) eachDefaultSystem mkApp flattenTreeSystem;
inherit (nixos) lib; inherit (nixos) lib;
inherit (lib) all removeSuffix recursiveUpdate genAttrs filterAttrs inherit (lib) recursiveUpdate filterAttrs mapAttrs;
mapAttrs;
inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules
genPackages pkgImport; genPackages pkgImport;
utils = import ./lib/utils.nix { inherit lib; }; utils = import ./lib/utils.nix { inherit lib; };
system = "x86_64-linux";
externOverlays = [ nur.overlay devshell.overlay ]; externOverlays = [ nur.overlay devshell.overlay ];
externModules = [ home.nixosModules.home-manager ]; externModules = [ home.nixosModules.home-manager ];
osSystem = "x86_64-linux";
outputs =
let
system = osSystem;
pkgset = pkgset =
let overlays = let
overlays =
(attrValues self.overlays) (attrValues self.overlays)
++ externOverlays ++ externOverlays
++ [ self.overlay ]; ++ [ self.overlay ];
@ -36,11 +39,11 @@
genPkgset { genPkgset {
inherit master nixos overlays system; inherit master nixos overlays system;
}; };
in
outputs = { {
nixosConfigurations = nixosConfigurations =
import ./hosts (recursiveUpdate inputs { import ./hosts (recursiveUpdate inputs {
inherit lib pkgset system utils externModules; inherit lib pkgset utils externModules system;
}); });
overlay = import ./pkgs; overlay = import ./pkgs;
@ -57,49 +60,48 @@
}; };
in in
(eachDefaultSystem (eachDefaultSystem
(system': (system:
let let
pkgs' = pkgImport { pkgs = pkgImport {
inherit system;
pkgs = master; pkgs = master;
system = system';
overlays = [ devshell.overlay ]; overlays = [ devshell.overlay ];
}; };
packages' = genPackages { packages = filterAttrs
overlay = self.overlay; (_: drv: drv.meta.broken != true)
overlays = self.overlays; (flattenTreeSystem system
pkgs = pkgs'; (genPackages {
}; inherit self pkgs;
})
);
filtered = filterAttrs
(_: v:
(v.meta ? platforms)
&& (elem system' v.meta.platforms)
&& (
(all (dev: dev.meta ? platforms) v.buildInputs)
&& (all (dev: elem system' dev.meta.platforms) v.buildInputs)
))
packages';
in in
{ {
inherit packages;
devShell = import ./shell.nix { devShell = import ./shell.nix {
pkgs = pkgs'; inherit pkgs;
}; };
apps = apps =
let let
validApps = attrNames (filterAttrs (_: drv: pathExists "${drv}/bin") validApps = attrNames (filterAttrs
self.packages."${system}"); (_: drv:
drv.meta.broken != true
&& pathExists "${drv}/bin"
)
self.packages."${osSystem}"
);
validSystems = attrNames filtered; validSystems = attrNames packages;
filterBins = filterAttrs filterBins = filterAttrs
(n: _: elem n validSystems && elem n validApps) (n: _: elem n validSystems && elem n validApps)
filtered; packages;
in in
mapAttrs (_: drv: mkApp { inherit drv; }) filterBins; mapAttrs (_: drv: mkApp { inherit drv; }) filterBins;
packages =
filtered;
})) // outputs; })) // outputs;
} }

View File

@ -82,8 +82,9 @@ in
(recursiveUpdate cachixAttrs modulesAttrs) (recursiveUpdate cachixAttrs modulesAttrs)
profilesAttrs; profilesAttrs;
genPackages = { overlay, overlays, pkgs }: genPackages = { self, pkgs }:
let let
inherit (self) overlay overlays;
packages = overlay pkgs pkgs; packages = overlay pkgs pkgs;
overlayPkgs = overlayPkgs =
genAttrs genAttrs