Something went wrong. Try again.
the configuration for all my nixos machines (hacky! bad! ugly!)
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128# Shamelessly copied from github.com/orual/flake because they basically nailed# it and I can't be assed to do this myself.let inherit (builtins) readDir hasAttr attrNames filter concatMap listToAttrs;
loadHosts = dir: inputs: let loadConf = dir: n: (import "${dir}/${n}" inputs) // {hostname = n;};
hosts' = let contents = readDir dir; in filter (n: contents."${n}" == "directory") (attrNames contents); in concatMap (n: let contents = readDir "${dir}/${n}"; hasDefault = (hasAttr "default.nix" contents) && (contents."default.nix" == "regular"); in if hasDefault then [(loadConf dir n)] else []) hosts';in { # Discover NixOS configurations. # It will find all sub-directories in `directory` and # include it if it has a default.nix. genNixOSHosts = { inputs, self, directory ? "${inputs.self}/hosts", nixpkgs ? inputs.nixpkgs, builder ? nixpkgs.lib.nixosSystem, specialArgs ? {}, baseModules ? [], overlays ? [], config ? {allowUnfree = true;}, }: let mkHost = { system, modules, hostname, }: builder { inherit system;
specialArgs = {inherit inputs self;} // specialArgs;
modules = [ ({...}: { networking.hostName = hostname;
nixpkgs = {inherit overlays config;}; }) ] ++ baseModules ++ modules; }; in listToAttrs (map (conf: { name = conf.hostname; # nix (2.34+) resolves bare `.#nixosConfigurations.<name>` build paths # by reading a string `type` attribute; the module system's own `type` # (an option-type set) breaks that resolution, so override it. value = (mkHost (removeAttrs conf ["home"])) // {type = "nixos-configuration";}; }) (loadHosts directory inputs));
# Discover home-manager configurations. # It will find all sub-directories in `directory` and # include it if it has a default.nix. genHomeHosts = { inputs, user, directory ? "${inputs.self}/hosts", nixpkgs ? inputs.nixpkgs, home ? inputs.home, builder ? home.lib.homeManagerConfiguration, specialArgs ? {}, baseModules ? [], overlays ? [], config ? {allowUnfree = true;}, }: let homeHosts = concatMap (h: if (hasAttr "home" h) then [((removeAttrs h ["home" "modules"]) // h.home)] else []) (loadHosts directory inputs);
mkHost = { system, modules, hostname, }: let pkgs = import nixpkgs {inherit system config overlays;}; in builder { inherit pkgs; extraSpecialArgs = {inherit inputs;} // specialArgs;
modules = [ ({lib, ...}: { home.username = lib.mkDefault user; home.homeDirectory = lib.mkDefault "/home/${user}"; }) ] ++ baseModules ++ modules; }; in listToAttrs (map (conf: { name = "${user}@${conf.hostname}"; # nix (2.34+) resolves bare `.#homeConfigurations.<name>` build paths # by reading a string `type` attribute; the module system's own `type` # (an option-type set) breaks that resolution, so override it. The # home-manager CLI only uses `.activationPackage`, so this is safe. value = (mkHost conf) // {type = "home-manager-configuration";}; }) homeHosts);}