diff --git a/nix/homes/rafiq/git.nix b/nix/homes/rafiq/git.nix deleted file mode 100644 index 62bb79b..0000000 --- a/nix/homes/rafiq/git.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ - flake.homes.rafiq = { - home.shellAliases = { - gs = "git status"; - gc = "git commit"; - gcam = "git commit -am"; - gu = "git push"; - gy = "git pull"; - gdh = "git diff HEAD"; - }; - programs.git = { - signing.signByDefault = true; - extraConfig = { - init.defaultBranch = "prime"; - push.autoSetupRemote = true; - pull.rebase = false; - core.editor = "$EDITOR"; - gpg.format = "ssh"; - }; - }; - }; -} diff --git a/nix/lib/default.nix b/nix/lib/default.nix index 0e94c00..b75aefc 100644 --- a/nix/lib/default.nix +++ b/nix/lib/default.nix @@ -5,92 +5,7 @@ let in { flake.lib = { - /** - Remove the top level attributes from an attribute set and return the merged attributes. - - # Inputs - - `attrset` - - : An attribute set to flatten. - - # Type - - ``` - flattenAttrs :: AttrSet -> AttrSet - ``` - - # Examples - :::{.example} - ## `flattenAttrs` usage example - - ```nix - flattenAttrs { x = { a = 1; b = 2; }; y = { c = 3; d = 4; }; } - => { a = 1; b = 2; c = 3; d = 4; } - ``` - */ flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset; - - /** - Return an attribute set for use with a option that needs to be used for all users. - - # Inputs - - `attrset` - - : An attribute set to apply to all the users. - - # Type - - ``` - forAllUsers :: AttrSet -> AttrSet - ``` - - # Examples - :::{.example} - ## `forAllUsers` usage example - - ```nix - flake.manifest.users.rafiq = { ... }; - flake.modules.nixos.default.users = forAllUsers { - isNormalUser = true; - }; - => flake.modules.nixos.default.users.rafiq.isNormalUser = true; - ``` - - ::: - */ - forAllUsers = attrset: mapAttrs (_: _: attrset) cfg.manifest.users; - - /** - Like forAllUsers, but passes in the name and value from the manifest. - - # Inputs - - `f` - - : A function that takes an attribute name and its value, and returns the new value for the attribute. - - # Type - - ``` - forAllUsers' :: (String -> Any -> Any) -> AttrSet - ``` - - # Examples - :::{.example} - ## `forAllUsers'` usage example - - ```nix - flake.manifest.users.rafiq = { ... }; - flake.modules.homeManager.users = forAllUsers' (name: value: { - home.username = name; - }); - => flake.modules.homeManager.default.users.rafiq.home.username = "rafiq"; - ``` - - ::: - */ - forAllUsers' = f: mapAttrs f cfg.manifest.users; + forAllUsers = f: mapAttrs f cfg.manifest.users; }; } diff --git a/nix/manifest.nix b/nix/manifest.nix index cd305e2..f3cd69c 100644 --- a/nix/manifest.nix +++ b/nix/manifest.nix @@ -15,7 +15,7 @@ in flake.manifest = { users.rafiq = { primary = true; - name = "Mohammad Rafiq"; + username = "rafiq"; # If we don't set this here we have to do some weird shit email = "rafiq@rrv.sh"; shell = "fish"; pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n rafiq"; diff --git a/nix/modules/git.nix b/nix/modules/git.nix deleted file mode 100644 index aee5432..0000000 --- a/nix/modules/git.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ - flake.modules.homeManager.default = - { manifest, config, ... }: - { - home.sessionVariables.GIT_CONFIG_GLOBAL = "$HOME/.config/git/config"; - programs.git = { - userName = manifest.users.${config.home.username}.name; - userEmail = manifest.users.${config.home.username}.email; - signing.key = "~/.ssh/id_ed25519.pub"; - }; - }; -} diff --git a/nix/modules/home-manager.nix b/nix/modules/home-manager.nix index 7b11f4d..2d6bf83 100644 --- a/nix/modules/home-manager.nix +++ b/nix/modules/home-manager.nix @@ -1,16 +1,14 @@ { inputs, config, ... }: let - inherit (cfg.lib) forAllUsers' flattenAttrs; + inherit (cfg.lib) flattenAttrs; cfg = config.flake; hm = inputs.home-manager; globalCfg = { useGlobalPkgs = true; useUserPackages = true; - extraSpecialArgs = { inherit (cfg) manifest; }; sharedModules = [ (flattenAttrs (cfg.modules.homeManager or { })) ]; - users = forAllUsers' (name: _: cfg.homes.${name}); }; in { diff --git a/nix/modules/hosts.nix b/nix/modules/hosts.nix index c2a87e0..ddcdf3c 100644 --- a/nix/modules/hosts.nix +++ b/nix/modules/hosts.nix @@ -18,7 +18,6 @@ let nixosSystem { specialArgs = { inherit inputs; - inherit (cfg) manifest; hostName = name; }; modules = [ diff --git a/nix/modules/shell.nix b/nix/modules/shell.nix deleted file mode 100644 index 865212f..0000000 --- a/nix/modules/shell.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ config, lib, ... }: -let - cfg = config.flake; - inherit (cfg.lib) forAllUsers'; - inherit (lib.attrsets) mapAttrs'; -in -{ - flake.modules.nixos.default = - { pkgs, ... }: - { - programs = mapAttrs' (name: value: { - name = value.shell; - value.enable = true; - }) cfg.manifest.users; - users.users = forAllUsers' (_: value: { shell = pkgs.${value.shell}; }); - }; - flake.modules.homeManager.default = - { config, ... }: - { - programs.${cfg.manifest.users.${config.home.username}.shell}.enable = true; - }; -} diff --git a/nix/modules/users.nix b/nix/modules/users.nix index 471dd15..6a423fd 100644 --- a/nix/modules/users.nix +++ b/nix/modules/users.nix @@ -1,31 +1,35 @@ { config, lib, ... }: let cfg = config.flake; - inherit (cfg.lib) forAllUsers'; - inherit (lib.lists) optional; + inherit (config.flake.lib) forAllUsers flattenAttrs; + inherit (lib.attrsets) filterAttrs; + owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) cfg.manifest.users); in { flake.modules.nixos.default = - { config, ... }: + { pkgs, config, ... }: { #TODO: move sudo/security options elsewhere - # security.sudo.wheelNeedsPassword = false; - # nix.settings.trusted-users = [ "@wheel" ]; + security.sudo.wheelNeedsPassword = false; + nix.settings.trusted-users = [ "@wheel" ]; + #TODO: move to shell config + programs.${owner.shell}.enable = true; #TODO: move ssh key settings elsewhere - # users.users.root.openssh.authorizedKeys.keys = [ owner.pubkey ]; users = { mutableUsers = false; groups.users.gid = 100; - users = forAllUsers' ( - _: value: { - isNormalUser = true; - extraGroups = optional (value.primary or false) "wheel"; - openssh.authorizedKeys.keys = [ value.pubkey ]; - } - ); + users.root.openssh.authorizedKeys.keys = [ owner.pubkey ]; + users.${owner.username} = { + isNormalUser = true; + # hashedPasswordFile + extraGroups = [ "wheel" ]; + shell = pkgs.${owner.shell}; + openssh.authorizedKeys.keys = [ owner.pubkey ]; + }; }; - home-manager.users = forAllUsers' ( + home-manager.users = forAllUsers ( name: _: { + #TODO: move into nixos/darwin config - should not apply to homeConfigurations home.username = name; home.homeDirectory = config.users.users.${name}.home; }