nixfiles/nixos/default.nix

119 lines
4.2 KiB
Nix
Raw Normal View History

{ lib, pkgsFlakes, hmFlakes, inputs, pkgs', modules, homeModules }:
2022-02-13 13:10:21 +00:00
let
inherit (builtins) attrValues mapAttrs;
inherit (lib) flatten optional optionals mkDefault mkForce;
inherit (lib.my) homeStateVersion;
2022-02-06 00:06:26 +00:00
2022-02-13 13:10:21 +00:00
mkSystem =
name: {
2022-02-06 00:06:26 +00:00
system,
2022-02-06 00:06:26 +00:00
nixpkgs ? "unstable",
home-manager ? nixpkgs,
hmNixpkgs ? home-manager,
2022-02-06 00:06:26 +00:00
config,
# This causes a (very slow) docs rebuild on every change to a module's options it seems
docCustom ? true,
2022-02-06 00:06:26 +00:00
}:
2022-02-13 13:10:21 +00:00
let
# The flake contains `nixosSystem`, so we do need it (if we didn't have the TODO hacked version anyway)
2022-02-13 13:10:21 +00:00
pkgsFlake = pkgsFlakes.${nixpkgs};
# TODO: This is mostly yoinked from nixpkgs/flake.nix master (as of 2022/02/11) since 21.11's version has hacky
# vm build stuff that breaks our impl. REMOVE WHEN 22.05 IS OUT!
nixosSystem' = args:
import "${pkgsFlake}/nixos/lib/eval-config.nix" (args // {
modules = args.modules ++ [{
system.nixos.versionSuffix =
".${lib.substring 0 8 pkgsFlake.lastModifiedDate}.${pkgsFlake.shortRev}";
system.nixos.revision = pkgsFlake.rev;
}];
});
modules' = [
2022-02-13 17:44:14 +00:00
# Importing modules from module args causes infinite recursion
inputs.impermanence.nixosModule
hmFlake.nixosModule
2022-02-13 17:44:14 +00:00
inputs.agenix.nixosModules.age
] ++ modules;
pkgs = pkgs'.${nixpkgs}.${system};
allPkgs = mapAttrs (_: p: p.${system}) pkgs';
hmFlake = hmFlakes.${home-manager};
in
nixosSystem' {
# Gotta override lib here unforunately, eval-config.nix likes to import its own (unextended) lib. We explicitly
# don't pass pkgs so that it'll be imported with modularly applied config and overlays.
lib = pkgs.lib;
# `baseModules` informs the manual which modules to document
baseModules =
(import "${pkgsFlake}/nixos/modules/module-list.nix") ++ (optionals docCustom modules');
modules = (optionals (!docCustom) modules') ++ [
(modArgs: {
warnings = flatten [
(optional (modArgs.config.home-manager.useGlobalPkgs && (nixpkgs != home-manager))
''
Using global nixpkgs ${nixpkgs} with home-manager ${home-manager} may cause problems.
'')
];
_module.args = {
inherit inputs;
pkgs' = allPkgs;
};
2022-02-13 13:48:11 +00:00
system.name = name;
networking.hostName = mkDefault name;
nixpkgs = {
inherit system;
# Make sure any previously set config / overlays (e.g. lib which will be inherited by home-manager down the
# line) are passed on when nixpkgs is imported.
inherit (pkgs) config overlays;
};
# Unfortunately it seems there's no way to fully decouple home-manager's lib from NixOS's pkgs.lib. :(
# https://github.com/nix-community/home-manager/blob/7c2ae0bdd20ddcaafe41ef669226a1df67f8aa06/nixos/default.nix#L22
home-manager = {
# Optimise if system and home-manager nixpkgs are the same
useGlobalPkgs = mkDefault (nixpkgs == home-manager);
sharedModules = homeModules ++ [
{
warnings = flatten [
(optional (!modArgs.config.home-manager.useGlobalPkgs && (hmNixpkgs != home-manager))
''
Using per-user nixpkgs ${hmNixpkgs} with home-manager ${home-manager} may cause issues.
'')
];
# pkgsPath is used by home-manager's nixkpgs module to import nixpkgs (i.e. if !useGlobalPkgs)
_module.args = {
inherit inputs;
pkgsPath = toString pkgsFlakes.${hmNixpkgs};
pkgs' = allPkgs;
};
}
(homeStateVersion home-manager)
];
};
})
2022-02-13 13:48:11 +00:00
config
];
2022-02-06 00:06:26 +00:00
};
2022-02-13 13:10:21 +00:00
in
mapAttrs mkSystem {
colony = {
system = "x86_64-linux";
nixpkgs = "stable";
home-manager = "unstable";
2022-02-13 13:10:21 +00:00
config = boxes/colony.nix;
docCustom = false;
2022-02-13 13:10:21 +00:00
};
2022-02-17 15:47:24 +00:00
installer = {
system = "x86_64-linux";
nixpkgs = "unstable";
config = ./installer.nix;
docCustom = false;
};
2022-02-13 13:10:21 +00:00
}