Move functions to helper.nix

This commit is contained in:
Fern Garden 2025-07-11 08:24:52 +08:00
parent 1bf5c9fb1d
commit 547c435ce8
2 changed files with 96 additions and 102 deletions

141
flake.nix
View file

@ -19,115 +19,52 @@
feishin-0_17_0.url = "github:NixOS/nixpkgs?ref=pull/414929/head"; # Feishin 0.17.0 feishin-0_17_0.url = "github:NixOS/nixpkgs?ref=pull/414929/head"; # Feishin 0.17.0
}; };
outputs = inputs @ { outputs = {
nixpkgs,
lanzaboote, lanzaboote,
nixos-hardware, nixos-hardware,
nixvim,
sops-nix, sops-nix,
fluffychat-2_0_0,
feishin-0_17_0,
... ...
}: } @ inputs: let
with nixpkgs.lib; let helpers = import ./helpers.nix inputs;
mkHost = { inherit (helpers) mergeHosts mkHost;
hostname, in
suite, mergeHosts [
platform ? "x86_64-linux", (mkHost "muskduck" {
user ? "fern", suite = "laptop";
extraModules ? [], extraModules = [
}: lanzaboote.nixosModules.lanzaboote
nixosSystem rec { nixos-hardware.nixosModules.lenovo-thinkpad-t480
system = platform; ];
})
pkgs = import nixpkgs { (mkHost "weebill" {
inherit system; suite = "server";
config = { platform = "aarch64-linux";
allowUnfree = true; user = "docker";
permittedInsecurePackages = [ extraModules = [
"dotnet-sdk-6.0.428" nixos-hardware.nixosModules.raspberry-pi-4
"dotnet-runtime-6.0.36" ];
]; })
};
};
specialArgs = { (mkHost "docker" {
inherit suite = "vm";
nixpkgs user = "docker";
hostname })
suite
platform
user
; # Inherit variables.
userPackages = { (mkHost "minecraft" {
fluffychat = fluffychat-2_0_0.legacyPackages.${system}.fluffychat; suite = "vm";
feishin = feishin-0_17_0.legacyPackages.${system}.feishin; user = "docker";
webone = pkgs.callPackage ./packages/webone {}; })
};
secrets = builtins.toString inputs.secrets; # Secrets directory. (mkHost "technitium" {
}; suite = "lxc";
})
modules = (mkHost "firefox-syncserver" {
[ suite = "lxc";
nixvim.nixosModules.nixvim extraModules = [
./suites/common.nix sops-nix.nixosModules.sops
./suites/${suite}.nix ];
./hosts/${suite}/${hostname}.nix })
] ];
++ (filesystem.listFilesRecursive ./modules)
++ extraModules;
};
in {
nixosConfigurations = {
# Laptops.
muskduck = mkHost {
hostname = "muskduck";
suite = "laptop";
extraModules = [
lanzaboote.nixosModules.lanzaboote
nixos-hardware.nixosModules.lenovo-thinkpad-t480
];
};
# Servers.
weebill = mkHost {
hostname = "weebill";
suite = "server";
platform = "aarch64-linux";
user = "docker";
extraModules = [
nixos-hardware.nixosModules.raspberry-pi-4
];
};
# Virtual machines.
vm-docker = mkHost {
hostname = "docker";
suite = "vm";
user = "docker";
};
vm-minecraft = mkHost {
hostname = "minecraft";
suite = "vm";
user = "docker";
};
# LXC containers.
lxc-technitium = mkHost {
hostname = "technitium";
suite = "lxc";
};
lxc-firefox-syncserver = mkHost {
hostname = "firefox-syncserver";
suite = "lxc";
extraModules = [
sops-nix.nixosModules.sops
];
};
};
};
} }

57
helpers.nix Normal file
View file

@ -0,0 +1,57 @@
inputs:
with inputs;
with inputs.nixpkgs.lib; {
mergeHosts = lists.foldl' (
a: b: attrsets.recursiveUpdate a b
) {};
mkHost = hostname: {
platform ? "x86_64-linux",
suite,
user ? "fern",
extraModules ? [],
}: {
nixosConfigurations.${hostname} = nixosSystem rec {
system = platform;
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
permittedInsecurePackages = [
"dotnet-sdk-6.0.428"
"dotnet-runtime-6.0.36"
];
};
};
specialArgs = {
inherit
hostname
nixpkgs
suite
platform
user
; # Inherit variables.
userPackages = {
fluffychat = fluffychat-2_0_0.legacyPackages.${system}.fluffychat;
feishin = feishin-0_17_0.legacyPackages.${system}.feishin;
webone = pkgs.callPackage ./packages/webone {};
};
secrets = builtins.toString inputs.secrets; # Secrets directory.
};
modules =
[
nixvim.nixosModules.nixvim
./suites/common.nix
./suites/${suite}.nix
./hosts/${suite}/${hostname}.nix
]
++ (filesystem.listFilesRecursive ./modules)
++ extraModules;
};
};
}