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
|
in
|
||||||
{
|
{
|
||||||
flake.lib = {
|
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;
|
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 = {
|
flake.manifest = {
|
||||||
users.rafiq = {
|
users.rafiq = {
|
||||||
primary = true;
|
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";
|
email = "rafiq@rrv.sh";
|
||||||
shell = "fish";
|
shell = "fish";
|
||||||
pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n rafiq";
|
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, ... }:
|
{ inputs, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (cfg.lib) flattenAttrs;
|
inherit (cfg.lib) forAllUsers' flattenAttrs;
|
||||||
cfg = config.flake;
|
cfg = config.flake;
|
||||||
hm = inputs.home-manager;
|
hm = inputs.home-manager;
|
||||||
globalCfg = {
|
globalCfg = {
|
||||||
useGlobalPkgs = true;
|
useGlobalPkgs = true;
|
||||||
useUserPackages = true;
|
useUserPackages = true;
|
||||||
|
extraSpecialArgs = { inherit (cfg) manifest; };
|
||||||
sharedModules = [
|
sharedModules = [
|
||||||
(flattenAttrs (cfg.modules.homeManager or { }))
|
(flattenAttrs (cfg.modules.homeManager or { }))
|
||||||
];
|
];
|
||||||
|
users = forAllUsers' (name: _: cfg.homes.${name});
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,7 @@ let
|
||||||
nixosSystem {
|
nixosSystem {
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit inputs;
|
inherit inputs;
|
||||||
|
inherit (cfg) manifest;
|
||||||
hostName = name;
|
hostName = name;
|
||||||
};
|
};
|
||||||
modules = [
|
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, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.flake;
|
cfg = config.flake;
|
||||||
inherit (config.flake.lib) forAllUsers flattenAttrs;
|
inherit (cfg.lib) forAllUsers';
|
||||||
inherit (lib.attrsets) filterAttrs;
|
inherit (lib.lists) optional;
|
||||||
owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) cfg.manifest.users);
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.modules.nixos.default =
|
flake.modules.nixos.default =
|
||||||
{ pkgs, config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
#TODO: move sudo/security options elsewhere
|
#TODO: move sudo/security options elsewhere
|
||||||
security.sudo.wheelNeedsPassword = false;
|
# security.sudo.wheelNeedsPassword = false;
|
||||||
nix.settings.trusted-users = [ "@wheel" ];
|
# nix.settings.trusted-users = [ "@wheel" ];
|
||||||
#TODO: move to shell config
|
|
||||||
programs.${owner.shell}.enable = true;
|
|
||||||
#TODO: move ssh key settings elsewhere
|
#TODO: move ssh key settings elsewhere
|
||||||
|
# users.users.root.openssh.authorizedKeys.keys = [ owner.pubkey ];
|
||||||
users = {
|
users = {
|
||||||
mutableUsers = false;
|
mutableUsers = false;
|
||||||
groups.users.gid = 100;
|
groups.users.gid = 100;
|
||||||
users.root.openssh.authorizedKeys.keys = [ owner.pubkey ];
|
users = forAllUsers' (
|
||||||
users.${owner.username} = {
|
_: value: {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
# hashedPasswordFile
|
extraGroups = optional (value.primary or false) "wheel";
|
||||||
extraGroups = [ "wheel" ];
|
openssh.authorizedKeys.keys = [ value.pubkey ];
|
||||||
shell = pkgs.${owner.shell};
|
}
|
||||||
openssh.authorizedKeys.keys = [ owner.pubkey ];
|
);
|
||||||
};
|
|
||||||
};
|
};
|
||||||
home-manager.users = forAllUsers (
|
home-manager.users = forAllUsers' (
|
||||||
name: _: {
|
name: _: {
|
||||||
#TODO: move into nixos/darwin config - should not apply to homeConfigurations
|
|
||||||
home.username = name;
|
home.username = name;
|
||||||
home.homeDirectory = config.users.users.${name}.home;
|
home.homeDirectory = config.users.users.${name}.home;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue