From 179bf31d5edc90c826dacf0b06b149469d8d14fa Mon Sep 17 00:00:00 2001 From: Kleidi Bujari Date: Sat, 5 Apr 2025 14:58:10 -0400 Subject: automate hosts gen and bump nixpkgs --- flake.nix | 97 ++++++++++++++++++--------------------------------------------- 1 file changed, 27 insertions(+), 70 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 605017b..a87c3f6 100644 --- a/flake.nix +++ b/flake.nix @@ -3,32 +3,18 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - disko.url = "github:nix-community/disko/v1.6.1"; + disko.url = "github:nix-community/disko/latest"; disko.inputs.nixpkgs.follows = "nixpkgs"; nixos-hardware.url = "github:nixos/nixos-hardware/master"; - - # Rust projects - naersk.url = "github:nix-community/naersk"; - naersk.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, ... } @ inputs: let - inherit (builtins) - attrNames - listToAttrs - map - readDir - ; + inherit (builtins) mapAttrs; inherit (nixpkgs) lib; - inherit (nixpkgs.lib) - mapAttrs - nixosSystem - ; - systems = [ "x86_64-linux" "aarch64-linux" ]; inherit (import ./lib/depot-tools.nix { inherit inputs systems lib; }) @@ -40,68 +26,39 @@ packages = eachSystem ( { newScope, ... }: mapAttrs (pname: { path, ... }: newScope { inherit pname; } path { }) - (importDir ./packages) + (importDir ./packages lib.id) ); - publisherArgs = { - flake = self; - inherit inputs; - }; + nixosModules = importDir ./modules + (mapAttrs (_: { path, ... }: path)); - expectsPublisherArgs = - module: - builtins.isFunction module - && builtins.all (arg: builtins.elem arg (builtins.attrNames publisherArgs)) ( - builtins.attrNames (builtins.functionArgs module) - ); - - injectPublisherArgs = - modulePath: + nixosConfigurations = importDir ./machines ( + entries: let - module = import modulePath; - in - if expectsPublisherArgs module then - lib.setDefaultModuleLocation modulePath (module publisherArgs) - else - modulePath; - - nixosModules = mapAttrs (_: moduleDir: injectPublisherArgs moduleDir) - (mapAttrs (_: { path, ... }: path) (importDir ./modules)); - in - { - inherit packages nixosModules; + flake = self; - nixosConfigurations = listToAttrs ( - map - (name: { - inherit name; - value = nixosSystem rec { - system = "x86_64-linux"; - specialArgs = { - inherit inputs; - inherit (self) outputs; - inherit (systemArgs.${system}) flake perSystem; + defaultModule = { config, ... }: + let + perSystemArg = system: { + _module.args.perSystem = systemArgs.${system}.perSystem; }; - modules = [ - # Machine's specific configuration - ./machines/${name} - - # Implicitly import xnet - self.nixosModules.xnet - - # Global module - ({ inputs, ... }: { + in + { + imports = [ (perSystemArg config.nixpkgs.hostPlatform.system) ]; + }; - # Set system nixpkgs to flake input - nix.registry = { - nixpkgs.flake = inputs.nixpkgs; - depot.flake = self; - }; - }) + buildNixOS = hostName: entry: + lib.nixosSystem { + modules = [ + defaultModule + entry.path + nixosModules.xnet ]; + specialArgs = { inherit inputs flake hostName; }; }; - }) - (attrNames (readDir ./machines)) + in + mapAttrs buildNixOS entries ); - }; + in + { inherit packages nixosModules nixosConfigurations; }; } -- cgit v1.3.1