Hosts, Use directory-driven hosts in flake.nix
This adds some code to flake.nix to read the directory of hosts/ and find all hosts based on their host.nix file, and set the hostname based on the directory. I don't know enough about hostnames to know what are valid characters, but in the future this could allow a hostname such as "servers/madoka" which may be an issue. For now the structure is simple enough of "hosts/name" resulting in hostname "name" Another commit is planned which will do the same thing for users
This commit is contained in:
parent
86bc28d6d4
commit
ba5fd48569
3 changed files with 15 additions and 5 deletions
20
flake.nix
20
flake.nix
|
|
@ -15,6 +15,8 @@
|
||||||
outputs = { self, home-manager, nixpkgs, ... }@inputs: let
|
outputs = { self, home-manager, nixpkgs, ... }@inputs: let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
fs = pkgs.lib.fileset;
|
||||||
|
st = pkgs.lib.strings;
|
||||||
|
|
||||||
hostConfig = extraModules: nixpkgs.lib.nixosSystem {
|
hostConfig = extraModules: nixpkgs.lib.nixosSystem {
|
||||||
specialArgs = { inherit inputs; };
|
specialArgs = { inherit inputs; };
|
||||||
|
|
@ -23,6 +25,15 @@
|
||||||
./nixosModules
|
./nixosModules
|
||||||
] ++ extraModules;
|
] ++ extraModules;
|
||||||
};
|
};
|
||||||
|
hostFilter = { name, ...}: name == "host.nix";
|
||||||
|
hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts);
|
||||||
|
|
||||||
|
hosts = builtins.listToAttrs (map (path: {
|
||||||
|
value = hostConfig [ path ];
|
||||||
|
name = builtins.unsafeDiscardStringContext (st.removeSuffix "/host.nix" (
|
||||||
|
builtins.elemAt (st.splitString "/hosts/" path) 1
|
||||||
|
));
|
||||||
|
}) hostPaths);
|
||||||
|
|
||||||
userConfig = extraModules: home-manager.lib.homeManagerConfiguration {
|
userConfig = extraModules: home-manager.lib.homeManagerConfiguration {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
|
|
@ -31,12 +42,11 @@
|
||||||
./hmModules
|
./hmModules
|
||||||
] ++ extraModules;
|
] ++ extraModules;
|
||||||
};
|
};
|
||||||
in
|
|
||||||
{
|
|
||||||
nixosConfigurations.onizuka = hostConfig [ ./hosts/onizuka ];
|
|
||||||
homeConfigurations."pan@onizuka" = userConfig [ ./hosts/onizuka/users/pan ];
|
|
||||||
|
|
||||||
nixosConfigurations.jibril = hostConfig [ ./hosts/jibril ];
|
in {
|
||||||
|
nixosConfigurations = hosts;
|
||||||
|
|
||||||
|
homeConfigurations."pan@onizuka" = userConfig [ ./hosts/onizuka/users/pan ];
|
||||||
homeConfigurations."pan@jibril" = userConfig [ ./hosts/jibril/users/pan ];
|
homeConfigurations."pan@jibril" = userConfig [ ./hosts/jibril/users/pan ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue