flake.nix/refactor: unify common logic

This commit is contained in:
2026-07-20 14:34:21 +02:00
parent 78676a8bc7
commit af0003f6db
+65 -105
View File
@@ -65,127 +65,87 @@
}:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs;
inherit (nixpkgs) lib;
# Build a host's nixosConfiguration from the shared boilerplate.
# Per-host differences are expressed as flags / extraModules rather
# than copy-pasted module blocks.
mkHost =
{ hostname # name of the ./<hostname> and ./home/<hostname> dirs
, system ? "x86_64-linux"
, homeHost ? hostname # which home/<...> config to use (iso reuses nixy)
, packages ? true # import common/packages.nix
, suspend ? true # import common/suspend.nix
, hardware ? true # import <hostname>/hardware-configuration.nix
, sops ? true # wire sops-nix
, hm ? true # wire home-manager
, hmBackup ? true # set home-manager.backupFileExtension
, nixosLib ? nixpkgs.lib # nixosSystem source (iso uses `nixos`)
, extraModules ? [ ]
}:
nixosLib.nixosSystem {
inherit system;
modules =
[
{ _module.args = inputs; }
{ _module.args.system = system; }
{ nix.registry.nixpkgs.flake = nixpkgs; }
]
++ lib.optional packages ./common/packages.nix
++ lib.optional suspend ./common/suspend.nix
++ [ (./. + "/${hostname}/configuration.nix") ]
++ lib.optional hardware (./. + "/${hostname}/hardware-configuration.nix")
++ lib.optional sops sops-nix.nixosModules.sops
++ lib.optionals hm [
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.akill = import (./home + "/${homeHost}/home.nix");
home-manager.extraSpecialArgs = { inherit inputs system; };
}
]
++ lib.optional (hm && hmBackup) { home-manager.backupFileExtension = "home_backup"; }
++ extraModules;
};
in
{
nixosConfigurations = {
nixy = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
modules = [
{ _module.args = inputs; }
{ _module.args.system = system; }
{ nix.registry.nixpkgs.flake = nixpkgs; }
./common/packages.nix
./common/suspend.nix
./nixy/configuration.nix
./nixy/hardware-configuration.nix
sops-nix.nixosModules.sops
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.akill = import ./home/nixy/home.nix;
home-manager.extraSpecialArgs = { inherit inputs system; };
home-manager.backupFileExtension = "home_backup";
}
];
};
nixy = mkHost { hostname = "nixy"; };
fuji = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
modules = [
{ _module.args = inputs; }
{ _module.args.system = system; }
{ nix.registry.nixpkgs.flake = nixpkgs; }
./common/packages.nix
./common/suspend.nix
./fuji/configuration.nix
./fuji/hardware-configuration.nix
sops-nix.nixosModules.sops
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.akill = import ./home/fuji/home.nix;
home-manager.extraSpecialArgs = { inherit inputs system; };
home-manager.backupFileExtension = "home_backup";
}
];
};
fuji = mkHost { hostname = "fuji"; };
nixy_iso = nixos.lib.nixosSystem rec {
system = "x86_64-linux";
modules = [
{ _module.args = inputs; }
{ _module.args.system = system; }
{ nix.registry.nixpkgs.flake = nixpkgs; }
nixy_iso = mkHost {
hostname = "nixy";
hardware = false;
nixosLib = nixos.lib;
extraModules = [
{ isoImage.squashfsCompression = "gzip -Xcompression-level 1"; }
./common/packages.nix
./common/suspend.nix
./nixy/configuration.nix
"${nixos}/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix"
sops-nix.nixosModules.sops
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.akill = import ./home/nixy/home.nix;
home-manager.extraSpecialArgs = { inherit inputs system; };
home-manager.backupFileExtension = "home_backup";
}
];
};
mediabox = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
modules = [
{ _module.args = inputs; }
{ _module.args.system = system; }
{ nix.registry.nixpkgs.flake = nixpkgs; }
./common/packages.nix
./common/suspend.nix
./mediabox/configuration.nix
./mediabox/hardware-configuration.nix
./modules/qbittorrent.nix
sops-nix.nixosModules.sops
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.akill = import ./home/mediabox/home.nix;
home-manager.extraSpecialArgs = { inherit inputs system; };
}
];
mediabox = mkHost {
hostname = "mediabox";
hmBackup = false;
extraModules = [ ./modules/qbittorrent.nix ];
};
blue = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
modules = [
{ _module.args = inputs; }
{ _module.args.system = system; }
{ nix.registry.nixpkgs.flake = nixpkgs; }
./blue/configuration.nix
./blue/hardware-configuration.nix
./common/packages.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.akill = import ./home/blue/home.nix;
home-manager.extraSpecialArgs = { inherit inputs system; };
}
];
blue = mkHost {
hostname = "blue";
suspend = false;
sops = false;
hmBackup = false;
};
magpie = nixpkgs.lib.nixosSystem rec {
magpie = mkHost {
hostname = "magpie";
system = "aarch64-linux";
modules = [
{ _module.args = inputs; }
{ _module.args.system = system; }
{ nix.registry.nixpkgs.flake = nixpkgs; }
./magpie/configuration.nix
./magpie/hardware-configuration.nix
packages = false;
suspend = false;
hm = false;
extraModules = [
simple-nixos-mailserver.nixosModule
sops-nix.nixosModules.sops
(builtins.toPath "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix")
];
};