Skip to content

Commit

Permalink
flake: simply packages with flattenTreeSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
nrdxp committed Jan 3, 2021
1 parent 51deae4 commit 41e3de0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 53 deletions.
106 changes: 54 additions & 52 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,102 @@
master.url = "nixpkgs/master";
nixos.url = "nixpkgs/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";
};

outputs = inputs@{ self, home, nixos, master, flake-utils, nur, devshell }:
let
inherit (builtins) attrNames attrValues readDir elem pathExists filter;
inherit (flake-utils.lib) eachDefaultSystem mkApp;
inherit (builtins) attrNames attrValues elem pathExists;
inherit (flake-utils.lib) eachDefaultSystem mkApp flattenTreeSystem;
inherit (nixos) lib;
inherit (lib) all removeSuffix recursiveUpdate genAttrs filterAttrs
mapAttrs;
inherit (lib) recursiveUpdate filterAttrs mapAttrs;
inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules
genPackages pkgImport;

utils = import ./lib/utils.nix { inherit lib; };

system = "x86_64-linux";

externOverlays = [ nur.overlay devshell.overlay ];
externModules = [ home.nixosModules.home-manager ];

pkgset =
let overlays =
(attrValues self.overlays)
++ externOverlays
++ [ self.overlay ];
in
genPkgset {
inherit master nixos overlays system;
};
osSystem = "x86_64-linux";

outputs = {
nixosConfigurations =
import ./hosts (recursiveUpdate inputs {
inherit lib pkgset system utils externModules;
});
outputs =
let
system = osSystem;
pkgset =
let
overlays =
(attrValues self.overlays)
++ externOverlays
++ [ self.overlay ];
in
genPkgset {
inherit master nixos overlays system;
};
in
{
nixosConfigurations =
import ./hosts (recursiveUpdate inputs {
inherit lib pkgset utils externModules system;
});

overlay = import ./pkgs;
overlay = import ./pkgs;

overlays = pathsToImportedAttrs overlayPaths;
overlays = pathsToImportedAttrs overlayPaths;

nixosModules = modules;
nixosModules = modules;

templates.flk.path = ./.;
templates.flk.path = ./.;

templates.flk.description = "flk template";
templates.flk.description = "flk template";

defaultTemplate = self.templates.flk;
};
defaultTemplate = self.templates.flk;
};
in
(eachDefaultSystem
(system':
(system:
let
pkgs' = pkgImport {
pkgs = pkgImport {
inherit system;
pkgs = master;
system = system';
overlays = [ devshell.overlay ];
};

packages' = genPackages {
overlay = self.overlay;
overlays = self.overlays;
pkgs = pkgs';
};
packages = filterAttrs
(_: drv: drv.meta.broken != true)
(flattenTreeSystem system
(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
{
inherit packages;

devShell = import ./shell.nix {
pkgs = pkgs';
inherit pkgs;
};

apps =
let
validApps = attrNames (filterAttrs (_: drv: pathExists "${drv}/bin")
self.packages."${system}");
validApps = attrNames (filterAttrs
(_: drv:
drv.meta.broken != true
&& pathExists "${drv}/bin"
)
self.packages."${osSystem}"
);

validSystems = attrNames filtered;
validSystems = attrNames packages;

filterBins = filterAttrs
(n: _: elem n validSystems && elem n validApps)
filtered;
packages;
in
mapAttrs (_: drv: mkApp { inherit drv; }) filterBins;

packages =
filtered;
})) // outputs;
}
3 changes: 2 additions & 1 deletion lib/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ in
(recursiveUpdate cachixAttrs modulesAttrs)
profilesAttrs;

genPackages = { overlay, overlays, pkgs }:
genPackages = { self, pkgs }:
let
inherit (self) overlay overlays;
packages = overlay pkgs pkgs;
overlayPkgs =
genAttrs
Expand Down

0 comments on commit 41e3de0

Please sign in to comment.