diff options
Diffstat (limited to 'util')
| -rw-r--r-- | util/default.nix | 16 | ||||
| -rw-r--r-- | util/host.nix | 49 | ||||
| -rw-r--r-- | util/user.nix | 109 |
3 files changed, 66 insertions, 108 deletions
diff --git a/util/default.nix b/util/default.nix index 0fb91b5..c3fa0b8 100644 --- a/util/default.nix +++ b/util/default.nix @@ -1,4 +1,14 @@ -{home-manager, ...}: { - host = import ./host.nix {}; - user = import ./user.nix {inherit home-manager;}; +{ + inputs, + lib, +}: let + mapFilterDirs = dir: filter: map: + with builtins; + with lib; let + dirs = filterAttrs filter (readDir dir); + in + mapAttrs map dirs; +in { + host = import ./host.nix {inherit lib inputs mapFilterDirs;}; + user = import ./user.nix {inherit lib inputs mapFilterDirs;}; } diff --git a/util/host.nix b/util/host.nix index 2c7906c..d100bfb 100644 --- a/util/host.nix +++ b/util/host.nix @@ -1,38 +1,45 @@ -_: { +{ + lib, + inputs, + mapFilterDirs, +}: rec { mkHost = { name, modules, - system ? "x86_64-linux", specialArgs ? {}, - version ? "22.11", + system ? "x86_64-linux", + stateVersion ? "22.11", pkgs, - }: { - ${name} = with pkgs.lib; + }: + with pkgs.lib; nixosSystem { inherit system specialArgs; modules = [ - ../hosts/common + ../profiles/base + ../profiles/nixos ../hosts/${name} - ({pkgs, ...}: { - system.stateVersion = version; + { + system.stateVersion = stateVersion; networking.hostName = mkDefault name; - - # enable non-free packages - nixpkgs.config = { - allowUnfree = true; - allowUnsupportedSystem = true; + nixpkgs = { + overlays = with inputs; [nur.overlay getchoo.overlays.default]; + config = { + allowUnfree = true; + allowUnsupportedSystem = true; + }; }; - - # Enable nix flakes - nix = { - package = pkgs.nixFlakes; - settings.experimental-features = ["nix-command" "flakes"]; - }; - }) + nix.registry.getchoo.flake = inputs.getchoo; + } ] ++ modules; }; - }; + + mapHosts = hosts: + mapFilterDirs ../hosts (_: v: v == "directory") (name: _: + mkHost { + inherit name; + inherit (hosts.${name}) modules system stateVersion pkgs; + }); } diff --git a/util/user.nix b/util/user.nix index 3953f11..c120e31 100644 --- a/util/user.nix +++ b/util/user.nix @@ -1,92 +1,33 @@ -{home-manager, ...}: let - commonHM = { - nixpkgs.config = { - allowUnfree = true; - allowUnsupportedSystem = true; - }; - xdg.configFile."nixpkgs/config.nix".text = '' - { - allowUnfree = true; - } - ''; - }; -in { +{ + lib, + inputs, + mapFilterDirs, + ... +}: rec { mkHMUser = { username, - channel, - modules ? [], + pkgs, stateVersion ? "22.11", - system ? "x86_64-linux", - extraSpecialArgs ? {}, - }: - home-manager.lib.homeManagerConfiguration { - pkgs = channel.legacyPackages.${system}; - inherit extraSpecialArgs; - modules = - [ - ../users/${username}/home.nix - ({pkgs, ...}: - { - home = { - inherit username stateVersion; - homeDirectory = "/home/${username}"; - }; - - programs.home-manager.enable = true; - nix = { - package = pkgs.nixFlakes; - settings.experimental-features = ["nix-command" "flakes"]; - }; - } - // commonHM) - ] - ++ modules; - }; - mkUser = { - username, - extraGroups ? [], - extraModules ? [], - extraSpecialArgs ? {}, - hashedPassword, - hm ? false, - shell, - stateVersion, - system ? "x86_64-linux", }: - [ - { - users.users.${username} = { - inherit extraGroups hashedPassword shell; - isNormalUser = true; - }; - } - ] - ++ extraModules - ++ ( - if hm - then [ - home-manager.nixosModules.home-manager + inputs.home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = [ + ../users/${username}/home.nix { - home-manager = { - inherit extraSpecialArgs; - useGlobalPkgs = true; - useUserPackages = true; - users.${username} = - { - imports = [ - ../users/${username}/home.nix - ]; - home.stateVersion = stateVersion; - } - // commonHM - // ( - if builtins.match ".*-linux" system != null - then {systemd.user.startServices = true;} - else {} - ); + home = { + inherit username stateVersion; + homeDirectory = "/home/${username}"; }; + + programs.home-manager.enable = true; } - ] - else [] - ); + ]; + }; + + mapHMUsers = users: + mapFilterDirs ../users (n: v: v == "directory" && n != "root") (username: _: + mkHMUser { + inherit username; + inherit (users.${username}) pkgs stateVersion; + }); } |
