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 let
pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgs; 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 in
{ {
nixosConfigurations = { nixosConfigurations = {
nixy = nixpkgs.lib.nixosSystem rec { nixy = mkHost { hostname = "nixy"; };
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";
}
];
};
fuji = nixpkgs.lib.nixosSystem rec { fuji = mkHost { hostname = "fuji"; };
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";
}
];
};
nixy_iso = nixos.lib.nixosSystem rec { nixy_iso = mkHost {
system = "x86_64-linux"; hostname = "nixy";
modules = [ hardware = false;
{ _module.args = inputs; } nixosLib = nixos.lib;
{ _module.args.system = system; } extraModules = [
{ nix.registry.nixpkgs.flake = nixpkgs; }
{ isoImage.squashfsCompression = "gzip -Xcompression-level 1"; } { 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" "${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 { mediabox = mkHost {
system = "x86_64-linux"; hostname = "mediabox";
modules = [ hmBackup = false;
{ _module.args = inputs; } extraModules = [ ./modules/qbittorrent.nix ];
{ _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; };
}
];
}; };
blue = nixpkgs.lib.nixosSystem rec { blue = mkHost {
system = "x86_64-linux"; hostname = "blue";
modules = [ suspend = false;
{ _module.args = inputs; } sops = false;
{ _module.args.system = system; } hmBackup = false;
{ 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; };
}
];
}; };
magpie = nixpkgs.lib.nixosSystem rec { magpie = mkHost {
hostname = "magpie";
system = "aarch64-linux"; system = "aarch64-linux";
modules = [ packages = false;
{ _module.args = inputs; } suspend = false;
{ _module.args.system = system; } hm = false;
{ nix.registry.nixpkgs.flake = nixpkgs; } extraModules = [
./magpie/configuration.nix
./magpie/hardware-configuration.nix
simple-nixos-mailserver.nixosModule simple-nixos-mailserver.nixosModule
sops-nix.nixosModules.sops
(builtins.toPath "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix") (builtins.toPath "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix")
]; ];
}; };