2021-02-02 01:57:19 +00:00
|
|
|
{ nixos, ... }:
|
2019-12-14 04:30:43 +00:00
|
|
|
let
|
2021-02-02 03:26:47 +00:00
|
|
|
inherit (builtins) attrNames attrValues isAttrs readDir listToAttrs mapAttrs
|
2021-02-03 23:41:21 +00:00
|
|
|
pathExists filter;
|
2019-12-14 04:30:43 +00:00
|
|
|
|
2021-02-02 01:57:19 +00:00
|
|
|
inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
|
2021-02-25 21:47:19 +00:00
|
|
|
recursiveUpdate genAttrs nixosSystem mkForce optionalAttrs;
|
2019-12-14 04:30:43 +00:00
|
|
|
|
|
|
|
# mapFilterAttrs ::
|
|
|
|
# (name -> value -> bool )
|
|
|
|
# (name -> value -> { name = any; value = any; })
|
|
|
|
# attrs
|
2020-01-04 05:06:31 +00:00
|
|
|
mapFilterAttrs = seive: f: attrs: filterAttrs seive (mapAttrs' f attrs);
|
2019-12-14 04:30:43 +00:00
|
|
|
|
2020-07-30 21:29:58 +00:00
|
|
|
# Generate an attribute set by mapping a function over a list of values.
|
|
|
|
genAttrs' = values: f: listToAttrs (map f values);
|
|
|
|
|
2021-01-19 07:51:23 +00:00
|
|
|
# pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs
|
2021-01-18 09:23:49 +00:00
|
|
|
pkgImport = nixpkgs: overlays: system:
|
|
|
|
import nixpkgs {
|
2020-12-25 19:53:57 +00:00
|
|
|
inherit system overlays;
|
|
|
|
config = { allowUnfree = true; };
|
|
|
|
};
|
|
|
|
|
|
|
|
# Convert a list to file paths to attribute set
|
|
|
|
# that has the filenames stripped of nix extension as keys
|
|
|
|
# and imported content of the file as value.
|
2021-01-19 07:51:23 +00:00
|
|
|
#
|
2020-12-25 19:53:57 +00:00
|
|
|
pathsToImportedAttrs = paths:
|
2021-02-04 02:35:10 +00:00
|
|
|
let
|
|
|
|
paths' = filter (hasSuffix ".nix") paths;
|
|
|
|
in
|
|
|
|
genAttrs' paths' (path: {
|
2020-12-25 19:53:57 +00:00
|
|
|
name = removeSuffix ".nix" (baseNameOf path);
|
|
|
|
value = import path;
|
|
|
|
});
|
|
|
|
|
|
|
|
overlayPaths =
|
|
|
|
let
|
|
|
|
overlayDir = ../overlays;
|
|
|
|
fullPath = name: overlayDir + "/${name}";
|
|
|
|
in
|
|
|
|
map fullPath (attrNames (readDir overlayDir));
|
2020-07-30 21:29:58 +00:00
|
|
|
|
2021-02-15 18:24:43 +00:00
|
|
|
/**
|
|
|
|
Synopsis: mkNodes _nixosConfigurations_
|
|
|
|
|
|
|
|
Generate the `nodes` attribute expected by deploy-rs
|
|
|
|
where _nixosConfigurations_ are `nodes`.
|
|
|
|
**/
|
|
|
|
mkNodes = deploy: mapAttrs (_: config: {
|
|
|
|
hostname = config.config.networking.hostName;
|
|
|
|
|
|
|
|
profiles.system = {
|
|
|
|
user = "root";
|
|
|
|
path = deploy.lib.x86_64-linux.activate.nixos config;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-02-06 20:30:17 +00:00
|
|
|
/**
|
2021-02-25 21:47:19 +00:00
|
|
|
Synopsis: mkProfileAttrs _path_
|
2021-02-06 20:30:17 +00:00
|
|
|
|
|
|
|
Recursively import the subdirs of _path_ containing a default.nix.
|
|
|
|
|
|
|
|
Example:
|
2021-02-25 21:47:19 +00:00
|
|
|
let profiles = mkProfileAttrs ./profiles; in
|
2021-02-06 20:30:17 +00:00
|
|
|
assert profiles ? core.default; 0
|
|
|
|
**/
|
2021-02-25 21:47:19 +00:00
|
|
|
mkProfileAttrs = dir:
|
2021-02-02 03:26:47 +00:00
|
|
|
let
|
2021-02-06 20:30:17 +00:00
|
|
|
imports =
|
|
|
|
let
|
|
|
|
files = readDir dir;
|
|
|
|
|
|
|
|
p = n: v:
|
|
|
|
v == "directory"
|
2021-02-25 21:47:19 +00:00
|
|
|
&& n != "profiles";
|
2021-02-06 20:30:17 +00:00
|
|
|
in
|
|
|
|
filterAttrs p files;
|
|
|
|
|
|
|
|
f = n: _:
|
2021-02-25 21:47:19 +00:00
|
|
|
optionalAttrs
|
|
|
|
(pathExists "${dir}/${n}/default.nix")
|
|
|
|
{ default = "${dir}/${n}"; }
|
|
|
|
// mkProfileAttrs "${dir}/${n}";
|
2021-02-02 03:26:47 +00:00
|
|
|
in
|
2021-02-06 20:30:17 +00:00
|
|
|
mapAttrs f imports;
|
2021-02-02 03:26:47 +00:00
|
|
|
|
2021-01-19 07:51:23 +00:00
|
|
|
in
|
|
|
|
{
|
2021-02-25 21:47:19 +00:00
|
|
|
inherit mkProfileAttrs mapFilterAttrs genAttrs' pkgImport
|
2021-02-15 18:24:43 +00:00
|
|
|
pathsToImportedAttrs mkNodes;
|
2021-01-19 07:51:23 +00:00
|
|
|
|
|
|
|
overlays = pathsToImportedAttrs overlayPaths;
|
|
|
|
|
2021-02-04 06:44:58 +00:00
|
|
|
genPkgs = { self }:
|
|
|
|
let inherit (self) inputs;
|
|
|
|
in
|
2021-02-15 05:11:49 +00:00
|
|
|
(inputs.utils.lib.eachDefaultSystem
|
2021-02-04 06:44:58 +00:00
|
|
|
(system:
|
|
|
|
let
|
|
|
|
extern = import ../extern { inherit inputs; };
|
2021-02-14 02:38:20 +00:00
|
|
|
overridePkgs = pkgImport inputs.override [ ] system;
|
|
|
|
overridesOverlay = (import ../overrides).packages;
|
2021-02-04 06:44:58 +00:00
|
|
|
|
|
|
|
overlays = [
|
2021-02-14 02:38:20 +00:00
|
|
|
(overridesOverlay overridePkgs)
|
2021-02-04 06:44:58 +00:00
|
|
|
self.overlay
|
|
|
|
(final: prev: {
|
|
|
|
lib = (prev.lib or { }) // {
|
|
|
|
inherit (nixos.lib) nixosSystem;
|
|
|
|
flk = self.lib;
|
2021-02-15 05:11:49 +00:00
|
|
|
utils = inputs.utils.lib;
|
2021-02-04 06:44:58 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
]
|
|
|
|
++ (attrValues self.overlays)
|
|
|
|
++ extern.overlays;
|
|
|
|
in
|
|
|
|
{ pkgs = pkgImport nixos overlays system; }
|
|
|
|
)
|
|
|
|
).pkgs;
|
|
|
|
|
2021-02-02 03:26:47 +00:00
|
|
|
profileMap = map (profile: profile.default);
|
|
|
|
|
2020-01-04 05:06:31 +00:00
|
|
|
recImport = { dir, _import ? base: import "${dir}/${base}.nix" }:
|
2020-07-31 04:17:28 +00:00
|
|
|
mapFilterAttrs
|
|
|
|
(_: v: v != null)
|
|
|
|
(n: v:
|
|
|
|
if n != "default.nix" && hasSuffix ".nix" n && v == "regular"
|
|
|
|
then
|
|
|
|
let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name)
|
|
|
|
else
|
|
|
|
nameValuePair ("") (null))
|
|
|
|
(readDir dir);
|
2020-07-30 21:29:58 +00:00
|
|
|
|
2021-01-28 02:11:38 +00:00
|
|
|
nixosSystemExtended = { modules, ... } @ args:
|
2021-02-02 01:57:19 +00:00
|
|
|
nixosSystem (args // {
|
|
|
|
modules =
|
|
|
|
let
|
|
|
|
modpath = "nixos/modules";
|
|
|
|
cd = "installer/cd-dvd/installation-cd-minimal-new-kernel.nix";
|
2021-02-03 23:41:21 +00:00
|
|
|
ciConfig =
|
|
|
|
(nixosSystem (args // {
|
|
|
|
modules =
|
|
|
|
let
|
|
|
|
# remove host module
|
|
|
|
modules' = filter (x: ! x ? require) modules;
|
|
|
|
in
|
|
|
|
modules' ++ [
|
|
|
|
({ suites, ... }: {
|
|
|
|
imports = with suites;
|
|
|
|
allProfiles ++ allUsers;
|
|
|
|
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
|
|
|
|
fileSystems."/" = { device = "/dev/disk/by-label/nixos"; };
|
|
|
|
})
|
|
|
|
];
|
|
|
|
})).config;
|
|
|
|
|
2021-02-02 01:57:19 +00:00
|
|
|
isoConfig = (nixosSystem
|
|
|
|
(args // {
|
|
|
|
modules = modules ++ [
|
|
|
|
"${nixos}/${modpath}/${cd}"
|
|
|
|
({ config, ... }: {
|
|
|
|
isoImage.isoBaseName = "nixos-" + config.networking.hostName;
|
|
|
|
# confilcts with networking.wireless which might be slightly
|
|
|
|
# more useful on a stick
|
|
|
|
networking.networkmanager.enable = mkForce false;
|
|
|
|
# confilcts with networking.wireless
|
|
|
|
networking.wireless.iwd.enable = mkForce false;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
})).config;
|
|
|
|
in
|
|
|
|
modules ++ [{
|
|
|
|
system.build = {
|
|
|
|
iso = isoConfig.system.build.isoImage;
|
2021-02-03 23:41:21 +00:00
|
|
|
ci = ciConfig.system.build.toplevel;
|
2021-02-02 01:57:19 +00:00
|
|
|
};
|
|
|
|
}];
|
|
|
|
});
|
2021-01-28 02:11:38 +00:00
|
|
|
|
2021-01-19 07:51:23 +00:00
|
|
|
nixosModules =
|
2020-12-25 19:53:57 +00:00
|
|
|
let
|
|
|
|
# binary cache
|
|
|
|
cachix = import ../cachix.nix;
|
|
|
|
cachixAttrs = { inherit cachix; };
|
|
|
|
|
|
|
|
# modules
|
2021-02-14 02:38:20 +00:00
|
|
|
moduleList = import ../modules/module-list.nix;
|
2020-12-25 19:53:57 +00:00
|
|
|
modulesAttrs = pathsToImportedAttrs moduleList;
|
|
|
|
|
|
|
|
in
|
2021-02-02 03:26:47 +00:00
|
|
|
recursiveUpdate cachixAttrs modulesAttrs;
|
2020-12-25 19:53:57 +00:00
|
|
|
|
2021-02-04 06:44:58 +00:00
|
|
|
genHomeActivationPackages = { self }:
|
|
|
|
let hmConfigs =
|
|
|
|
builtins.mapAttrs
|
|
|
|
(_: config: config.config.home-manager.users)
|
|
|
|
self.nixosConfigurations;
|
|
|
|
in
|
2021-02-02 02:48:59 +00:00
|
|
|
mapAttrs
|
|
|
|
(_: x: mapAttrs
|
|
|
|
(_: cfg: cfg.home.activationPackage)
|
|
|
|
x)
|
|
|
|
hmConfigs;
|
2021-01-14 07:20:00 +00:00
|
|
|
|
2021-01-03 07:05:39 +00:00
|
|
|
genPackages = { self, pkgs }:
|
2020-12-25 19:53:57 +00:00
|
|
|
let
|
2021-01-03 07:05:39 +00:00
|
|
|
inherit (self) overlay overlays;
|
2021-01-18 09:23:49 +00:00
|
|
|
packagesNames = attrNames (overlay null null)
|
|
|
|
++ attrNames (fold
|
|
|
|
(attr: sum: recursiveUpdate sum attr)
|
|
|
|
{ }
|
|
|
|
(attrValues
|
|
|
|
(mapAttrs (_: v: v null null) overlays)
|
|
|
|
)
|
|
|
|
);
|
2020-12-25 19:53:57 +00:00
|
|
|
in
|
2021-01-18 09:23:49 +00:00
|
|
|
fold
|
|
|
|
(key: sum: recursiveUpdate sum {
|
|
|
|
${key} = pkgs.${key};
|
|
|
|
})
|
|
|
|
{ }
|
|
|
|
packagesNames;
|
2019-12-14 04:30:43 +00:00
|
|
|
}
|