From 547c435ce8a0af2e2853d9d8c9895df465e8e937 Mon Sep 17 00:00:00 2001 From: Fern Garden Date: Fri, 11 Jul 2025 08:24:52 +0800 Subject: [PATCH] Move functions to helper.nix --- flake.nix | 141 +++++++++++++++------------------------------------- helpers.nix | 57 +++++++++++++++++++++ 2 files changed, 96 insertions(+), 102 deletions(-) create mode 100644 helpers.nix diff --git a/flake.nix b/flake.nix index e171816..a9adae3 100755 --- a/flake.nix +++ b/flake.nix @@ -19,115 +19,52 @@ feishin-0_17_0.url = "github:NixOS/nixpkgs?ref=pull/414929/head"; # Feishin 0.17.0 }; - outputs = inputs @ { - nixpkgs, + outputs = { lanzaboote, nixos-hardware, - nixvim, sops-nix, - fluffychat-2_0_0, - feishin-0_17_0, ... - }: - with nixpkgs.lib; let - mkHost = { - hostname, - suite, - platform ? "x86_64-linux", - user ? "fern", - extraModules ? [], - }: - nixosSystem rec { - system = platform; + } @ inputs: let + helpers = import ./helpers.nix inputs; + inherit (helpers) mergeHosts mkHost; + in + mergeHosts [ + (mkHost "muskduck" { + suite = "laptop"; + extraModules = [ + lanzaboote.nixosModules.lanzaboote + nixos-hardware.nixosModules.lenovo-thinkpad-t480 + ]; + }) - pkgs = import nixpkgs { - inherit system; - config = { - allowUnfree = true; - permittedInsecurePackages = [ - "dotnet-sdk-6.0.428" - "dotnet-runtime-6.0.36" - ]; - }; - }; + (mkHost "weebill" { + suite = "server"; + platform = "aarch64-linux"; + user = "docker"; + extraModules = [ + nixos-hardware.nixosModules.raspberry-pi-4 + ]; + }) - specialArgs = { - inherit - nixpkgs - hostname - suite - platform - user - ; # Inherit variables. + (mkHost "docker" { + suite = "vm"; + user = "docker"; + }) - userPackages = { - fluffychat = fluffychat-2_0_0.legacyPackages.${system}.fluffychat; - feishin = feishin-0_17_0.legacyPackages.${system}.feishin; - webone = pkgs.callPackage ./packages/webone {}; - }; + (mkHost "minecraft" { + suite = "vm"; + user = "docker"; + }) - secrets = builtins.toString inputs.secrets; # Secrets directory. - }; + (mkHost "technitium" { + suite = "lxc"; + }) - 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"; - 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 - ]; - }; - }; - }; + (mkHost "firefox-syncserver" { + suite = "lxc"; + extraModules = [ + sops-nix.nixosModules.sops + ]; + }) + ]; } diff --git a/helpers.nix b/helpers.nix new file mode 100644 index 0000000..991c633 --- /dev/null +++ b/helpers.nix @@ -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; + }; + }; +}