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

101
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",
extraModules ? [],
}:
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
nixpkgs
hostname
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;
};
in {
nixosConfigurations = {
# Laptops.
muskduck = mkHost {
hostname = "muskduck";
suite = "laptop"; suite = "laptop";
extraModules = [ extraModules = [
lanzaboote.nixosModules.lanzaboote lanzaboote.nixosModules.lanzaboote
nixos-hardware.nixosModules.lenovo-thinkpad-t480 nixos-hardware.nixosModules.lenovo-thinkpad-t480
]; ];
}; })
# Servers. (mkHost "weebill" {
weebill = mkHost {
hostname = "weebill";
suite = "server"; suite = "server";
platform = "aarch64-linux"; platform = "aarch64-linux";
user = "docker"; user = "docker";
extraModules = [ extraModules = [
nixos-hardware.nixosModules.raspberry-pi-4 nixos-hardware.nixosModules.raspberry-pi-4
]; ];
}; })
# Virtual machines. (mkHost "docker" {
vm-docker = mkHost {
hostname = "docker";
suite = "vm"; suite = "vm";
user = "docker"; user = "docker";
}; })
vm-minecraft = mkHost { (mkHost "minecraft" {
hostname = "minecraft";
suite = "vm"; suite = "vm";
user = "docker"; user = "docker";
}; })
# LXC containers. (mkHost "technitium" {
lxc-technitium = mkHost {
hostname = "technitium";
suite = "lxc"; suite = "lxc";
}; })
lxc-firefox-syncserver = mkHost { (mkHost "firefox-syncserver" {
hostname = "firefox-syncserver";
suite = "lxc"; suite = "lxc";
extraModules = [ extraModules = [
sops-nix.nixosModules.sops 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;
};
};
}