Compare commits
6 commits
de72f9a869
...
63fef3193e
Author | SHA1 | Date | |
---|---|---|---|
63fef3193e | |||
9fb9598d16 | |||
724794eb8b | |||
f7d404494f | |||
c56e3e5eba | |||
28076ee149 |
8 changed files with 161 additions and 21 deletions
22
nix/homes/rafiq/git.nix
Normal file
22
nix/homes/rafiq/git.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
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";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -5,7 +5,92 @@ 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;
|
||||
forAllUsers = f: mapAttrs f cfg.manifest.users;
|
||||
|
||||
/**
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ in
|
|||
flake.manifest = {
|
||||
users.rafiq = {
|
||||
primary = true;
|
||||
username = "rafiq"; # If we don't set this here we have to do some weird shit
|
||||
name = "Mohammad Rafiq";
|
||||
email = "rafiq@rrv.sh";
|
||||
shell = "fish";
|
||||
pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n rafiq";
|
||||
|
|
12
nix/modules/git.nix
Normal file
12
nix/modules/git.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
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";
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
{ inputs, config, ... }:
|
||||
let
|
||||
inherit (cfg.lib) flattenAttrs;
|
||||
inherit (cfg.lib) forAllUsers' 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
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ let
|
|||
nixosSystem {
|
||||
specialArgs = {
|
||||
inherit inputs;
|
||||
inherit (cfg) manifest;
|
||||
hostName = name;
|
||||
};
|
||||
modules = [
|
||||
|
|
22
nix/modules/shell.nix
Normal file
22
nix/modules/shell.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{ 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;
|
||||
};
|
||||
}
|
|
@ -1,35 +1,31 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
cfg = config.flake;
|
||||
inherit (config.flake.lib) forAllUsers flattenAttrs;
|
||||
inherit (lib.attrsets) filterAttrs;
|
||||
owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) cfg.manifest.users);
|
||||
inherit (cfg.lib) forAllUsers';
|
||||
inherit (lib.lists) optional;
|
||||
in
|
||||
{
|
||||
flake.modules.nixos.default =
|
||||
{ pkgs, config, ... }:
|
||||
{ config, ... }:
|
||||
{
|
||||
#TODO: move sudo/security options elsewhere
|
||||
security.sudo.wheelNeedsPassword = false;
|
||||
nix.settings.trusted-users = [ "@wheel" ];
|
||||
#TODO: move to shell config
|
||||
programs.${owner.shell}.enable = true;
|
||||
# security.sudo.wheelNeedsPassword = false;
|
||||
# nix.settings.trusted-users = [ "@wheel" ];
|
||||
#TODO: move ssh key settings elsewhere
|
||||
# users.users.root.openssh.authorizedKeys.keys = [ owner.pubkey ];
|
||||
users = {
|
||||
mutableUsers = false;
|
||||
groups.users.gid = 100;
|
||||
users.root.openssh.authorizedKeys.keys = [ owner.pubkey ];
|
||||
users.${owner.username} = {
|
||||
users = forAllUsers' (
|
||||
_: value: {
|
||||
isNormalUser = true;
|
||||
# hashedPasswordFile
|
||||
extraGroups = [ "wheel" ];
|
||||
shell = pkgs.${owner.shell};
|
||||
openssh.authorizedKeys.keys = [ owner.pubkey ];
|
||||
extraGroups = optional (value.primary or false) "wheel";
|
||||
openssh.authorizedKeys.keys = [ value.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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue