Skip to content

Commit

Permalink
flake: initial multiArch support
Browse files Browse the repository at this point in the history
* Employ new package semantics to ensure that packages only show up in
flake outputs in which they are actually supported.
* use flake-utils to ease multiArch delcarations
* refactor flake.nix into multiArch and regular outputs
  • Loading branch information
nrdxp committed Aug 4, 2020
1 parent a4e3c8a commit ef86717
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 65 deletions.
16 changes: 16 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 74 additions & 63 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,98 @@
master.url = "nixpkgs/master";
nixos.url = "nixpkgs/release-20.03";
home.url = "github:rycee/home-manager/bqv-flakes";
futils.url = "github:numtide/flake-utils";
};

outputs = inputs@{ self, home, nixos, master }:
outputs = inputs@{ self, home, nixos, master, futils }:
let
inherit (builtins) attrNames attrValues readDir;
inherit (nixos) lib;
inherit (lib) removeSuffix recursiveUpdate genAttrs filterAttrs;
inherit (utils) pathsToImportedAttrs;
inherit (lib) recursiveUpdate;
inherit (utils) pathsToImportedAttrs overlaysToPkgs;
inherit (futils.lib) eachSystem defaultSystems;

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

system = "x86_64-linux";
systems = defaultSystems ++ [ "armv7l-linux" ];

pkgImport = pkgs:
pkgImport = pkgs: system:
import pkgs {
inherit system;
overlays = attrValues self.overlays;
config = { allowUnfree = true; };
};

pkgset = {
osPkgs = pkgImport nixos;
pkgs = pkgImport master;
pkgset = system: {
osPkgs = pkgImport nixos system;
pkgs = pkgImport master system;
};

in
with pkgset;
{
nixosConfigurations =
import ./hosts (recursiveUpdate inputs {
inherit lib pkgset system utils;
}
);

devShell."${system}" = import ./shell.nix {
inherit pkgs;
};

overlay = import ./pkgs;

overlays =
let
overlayDir = ./overlays;
fullPath = name: overlayDir + "/${name}";
overlayPaths = map fullPath (attrNames (readDir overlayDir));
in
pathsToImportedAttrs overlayPaths;

packages."${system}" =
let
packages = self.overlay osPkgs osPkgs;
overlays = lib.filterAttrs (n: v: n != "pkgs") self.overlays;
overlayPkgs =
genAttrs
(attrNames overlays)
(name: (overlays."${name}" osPkgs osPkgs)."${name}");
in
recursiveUpdate packages overlayPkgs;

nixosModules =
multiSystemOutputs = eachSystem systems (system:
let
# binary cache
cachix = import ./cachix.nix;
cachixAttrs = { inherit cachix; };

# modules
moduleList = import ./modules/list.nix;
modulesAttrs = pathsToImportedAttrs moduleList;

# profiles
profilesList = import ./profiles/list.nix;
profilesAttrs = { profiles = pathsToImportedAttrs profilesList; };

pkgset' = pkgset system;
in
recursiveUpdate
(recursiveUpdate cachixAttrs modulesAttrs)
profilesAttrs;

templates.flk.path = ./.;
templates.flk.description = "flk template";
with pkgset';
{
devShell = import ./shell.nix {
inherit pkgs;
};

defaultTemplate = self.templates.flk;
};
packages = overlaysToPkgs self.overlays osPkgs;
}
);

outputs = {
nixosConfigurations =
let
system = "x86_64-linux";
pkgset' = pkgset system;

in
import ./hosts (recursiveUpdate inputs {
inherit lib system utils;
pkgset = pkgset';
}
);

nixosModules =
let
# binary cache
cachix = import ./cachix.nix;
cachixAttrs = { inherit cachix; };

# modules
moduleList = import ./modules/list.nix;
modulesAttrs = pathsToImportedAttrs moduleList;

# profiles
profilesList = import ./profiles/list.nix;
profilesAttrs = { profiles = pathsToImportedAttrs profilesList; };

in
recursiveUpdate
(recursiveUpdate cachixAttrs modulesAttrs)
profilesAttrs;

overlay = import ./pkgs;

overlays =
let
overlayDir = ./overlays;
fullPath = name: overlayDir + "/${name}";
overlayPaths = map fullPath (attrNames (readDir overlayDir));
in
pathsToImportedAttrs overlayPaths;

defaultTemplate = self.templates.flk;

templates = {
flk = {
path = ./.;
description = "flk template";
};
};
};
in
recursiveUpdate multiSystemOutputs outputs;
}
38 changes: 36 additions & 2 deletions lib/utils.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
{ lib, ... }:
let
inherit (builtins) attrNames isAttrs readDir listToAttrs;
inherit (builtins) attrNames attrValues isAttrs readDir listToAttrs;

inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix;
inherit (lib)
collect
filterAttrs
filterAttrsRecursive
getName
hasSuffix
isDerivation
mapAttrs'
mapAttrs
nameValuePair
removeSuffix;

# mapFilterAttrs ::
# (name -> value -> bool )
Expand Down Expand Up @@ -38,4 +48,28 @@ in
value = import path;
});

overlaysToPkgs = overlaysAttrs: pkgs:
let
overlayDrvs = mapAttrs (_: v: v pkgs pkgs) overlaysAttrs;

# some derivations fail to evaluate, simply remove them so we can move on
filterDrvs = filterAttrsRecursive
(_: v: (builtins.tryEval v).success)
overlayDrvs;

drvs = collect (isDerivation) filterDrvs;

# don't bother exporting a package if it's platform isn't supported
systemDrvs = builtins.filter
(drv: builtins.elem
pkgs.system
(drv.meta.platforms or [ ]))
drvs;

nvPairs = map
(drv: nameValuePair (getName drv) drv)
systemDrvs;
in
listToAttrs nvPairs;

}

0 comments on commit ef86717

Please sign in to comment.