my over complex system configurations dotfiles.isabelroses.com/
nixos nix flake dotfiles linux

refactor(hosts): improve the system builders

+57 -75
-1
hosts/amatarasu/default.nix
··· 21 21 }; 22 22 system = { 23 23 mainUser = "isabel"; 24 - hostname = "amatarasu"; 25 24 26 25 boot = { 27 26 loader = "systemd-boot";
-1
hosts/beta/default.nix
··· 12 12 }; 13 13 system = { 14 14 mainUser = "isabel"; 15 - hostname = "beta"; 16 15 17 16 boot = { 18 17 loader = "systemd-boot";
+47 -64
hosts/default.nix
··· 5 5 ... 6 6 }: let 7 7 inherit (self) inputs; 8 - inherit (lib) concatLists mkNixosSystem mkNixosIso; 8 + inherit (lib) mkMerge mapAttrs concatLists mkNixosSystem mkNixosIso; 9 9 10 10 # home manager modules from inputs 11 11 hm = inputs.home-manager.nixosModules.home-manager; ··· 44 44 45 45 # extraSpecialArgs that are on all machines 46 46 sharedArgs = {inherit inputs self lib;}; 47 - in { 48 - # super rubbish laptop 49 - hydra = mkNixosSystem { 50 - inherit withSystem; 51 - system = "x86_64-linux"; 52 - modules = 53 - [ 54 - ./hydra 55 - workstation 56 - laptop 57 - ] 58 - ++ concatLists [ 59 - shared 60 - homes 61 - ]; 62 - specialArgs = sharedArgs; 63 - }; 47 + in 48 + mkMerge [ 49 + (mapAttrs mkNixosSystem { 50 + # super rubbish laptop 51 + hydra = { 52 + inherit withSystem; 53 + system = "x86_64-linux"; 54 + modules = 55 + [ 56 + workstation 57 + laptop 58 + ] 59 + ++ concatLists [shared homes]; 60 + specialArgs = sharedArgs; 61 + }; 64 62 65 - # super cool gamer pc 66 - amatarasu = mkNixosSystem { 67 - inherit withSystem; 68 - system = "x86_64-linux"; 69 - modules = 70 - [ 71 - ./amatarasu 72 - desktop 73 - workstation 74 - ] 75 - ++ concatLists [shared homes]; 76 - specialArgs = sharedArgs; 77 - }; 63 + # super cool gamer pc 64 + amatarasu = { 65 + inherit withSystem; 66 + system = "x86_64-linux"; 67 + modules = 68 + [ 69 + desktop 70 + workstation 71 + ] 72 + ++ concatLists [shared homes]; 73 + specialArgs = sharedArgs; 74 + }; 78 75 79 - # hertzner cloud computer 80 - luz = mkNixosSystem { 81 - inherit withSystem; 82 - system = "x86_64-linux"; 83 - modules = 84 - [ 85 - ./luz 86 - server 87 - ] 88 - ++ concatLists [shared homes]; 89 - specialArgs = sharedArgs; 90 - }; 76 + # hertzner cloud computer 77 + luz = { 78 + inherit withSystem; 79 + system = "x86_64-linux"; 80 + modules = 81 + [ 82 + server 83 + ] 84 + ++ concatLists [shared homes]; 85 + specialArgs = sharedArgs; 86 + }; 87 + }) 91 88 92 - /* 93 - beta = mkNixosSystem { 94 - inherit withSystem; 95 - system = "x86_64-linux"; 96 - modules = [ 97 - ./beta 98 - server 99 - ] 100 - ++ concatLists [shared homes]; 101 - specialArgs = sharedArgs; 102 - }; 103 - */ 104 - 105 - lilith = mkNixosIso { 106 - system = "x86_64-linux"; 107 - modules = [ 108 - ./lilith 109 - ]; 110 - specialArgs = sharedArgs; 111 - }; 112 - } 89 + (mapAttrs mkNixosIso { 90 + lilith = { 91 + system = "x86_64-linux"; 92 + specialArgs = sharedArgs; 93 + }; 94 + }) 95 + ]
-1
hosts/hydra/default.nix
··· 17 17 18 18 system = { 19 19 mainUser = "isabel"; 20 - hostname = "hydra"; 21 20 22 21 boot = { 23 22 plymouth.enable = true;
-1
hosts/luz/default.nix
··· 17 17 }; 18 18 system = { 19 19 mainUser = "isabel"; 20 - hostname = "luz"; 21 20 22 21 boot = { 23 22 loader = "grub";
+10 -7
lib/builders.nix
··· 11 11 # mkNixosSystem wraps mkSystem (or lib.nixosSystem) with flake-parts' withSystem to give us inputs' and self' from flake-parts 12 12 # which can also be used as a template for nixos hosts with system type and modules to be imported with ease 13 13 # specialArgs is also defined here to avoid defining them for each host 14 - mkNixosSystem = { 14 + mkNixosSystem = host: { 15 15 modules, 16 16 system, 17 17 withSystem, ··· 23 23 ... 24 24 }: 25 25 mkSystem { 26 - inherit modules system; 26 + inherit system; 27 + modules = 28 + [ 29 + "${self}/hosts/${host}" 30 + {config.modules.system.hostname = host;} 31 + ] 32 + ++ args.modules or []; 27 33 specialArgs = {inherit lib inputs self inputs' self';} // args.specialArgs or {}; 28 34 }); 29 35 30 36 # mkIso is should be a set that extends mkSystem (again) with necessary modules to create an Iso image 31 37 # don't use mkNixosSystem as it is complelty overkill for an iso and will have too much data, we need a light weight image 32 - mkNixosIso = { 33 - modules, 34 - system, 35 - ... 36 - } @ args: 38 + mkNixosIso = host: {system, ...} @ args: 37 39 mkSystem { 38 40 inherit system; 39 41 specialArgs = {inherit inputs lib self;} // args.specialArgs or {}; ··· 42 44 # get an installer profile from nixpkgs to base the Isos off of 43 45 "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" 44 46 "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix" 47 + "${self}/hosts/${host}" 45 48 ] 46 49 ++ args.modules or []; 47 50 };