Skip to content

Commit

Permalink
Config updates
Browse files Browse the repository at this point in the history
- Add `os` alias
- Add `username` config option to make the flakes easier to adapt
- Make the home config name be passed down as arg
  • Loading branch information
KubqoA committed Oct 26, 2024
1 parent d61efae commit 5e97728
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 50 deletions.
19 changes: 17 additions & 2 deletions config.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# Global configuration options that can be referenced by all modules
# Autoloaded as a module by `makeHome` and `makeSystem` functions
{lib, ...}:
{
config,
lib,
system,
...
}:
with lib; {
options = {
username = mkOption {type = types.str;};
dotfilesPath = mkOption {type = types.str;};
gitSigningKey = mkOption {type = types.str;};
gpgSshControl = mkOption {type = types.str;};
sshPublicKey = mkOption {type = types.str;};
};

config = {
username = "jakub";
dotfilesPath =
lib.mkDefault
{
"x86_64-linux" = "/persist/dotfiles";
"aarch64-linux" = "/persist/dotfiles";
"aarch64-darwin" = "/Users/${config.username}/.config/dotfiles";
}
.${system};
gitSigningKey = "4EB39A80B52672EC";
gpgSshControl = "CC54AAD6EF69F323DEB5CDDF9521D2F679686C9E";
sshPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJP8m7CjSO/Rme3xkIAnvQrVi0AUnLGwDm5DoM6JucWj";
Expand Down
7 changes: 4 additions & 3 deletions hosts/harmonium/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
pkgs,
lib,
config,
inputs,
lib,
pkgs,
...
}: {
imports =
Expand Down Expand Up @@ -52,7 +53,7 @@
programs.sway.enable = true;
programs.light.enable = true;

users.users.jakub = {
users.users.${config.username} = {
# TODO: Research secret managers and use them to store the pass
hashedPassword = "$6$rounds=500000$0rEHES1LTcVCJYz3$9MnsxPUjY2fcMKIHdlzZB0KW/52gPIpe9ENWcfpUlAIzG75rC3hDotfr44k7MwVVc6Ri0ePZB.q7G3xNbSvCx.";
isNormalUser = true;
Expand Down
12 changes: 7 additions & 5 deletions hosts/nyckelharpa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ curl -L https://nixos.org/nix/install | sh
git clone [email protected]:KubqoA/dotfiles.git ~/.config/dotfiles
```

3. Install [`nix-darwin`](https://github.com/LnL7/nix-darwin?tab=readme-ov-file#flakes) and `home-manager`
3. Enter the dev shell and initialize the configs
```sh
nix run nix-darwin -- switch --flake ~/.config/dotfiles
nix run home-manager/master -- switch --flake "~/.config/dotfiles#jakub-macos"
nix develop
# Runs nix-darwin and home-manager
os nyckelharpa
hm jakub-macos
```

4. To apply further updates, run
```sh
dw switch # for darwin-rebuild switch
hm switch # for home-manager switch
os switch
hm switch
```
5 changes: 3 additions & 2 deletions hosts/nyckelharpa/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
config,
lib,
pkgs,
self,
Expand Down Expand Up @@ -27,7 +28,7 @@
zsh.enable = true;
};

users.users.jakub.home = "/Users/jakub";
users.users.${config.username}.home = "/Users/${config.username}";

security = {
# Add ability to use Touch ID for sudo
Expand All @@ -47,7 +48,7 @@
"/Applications/RubyMine.app"
"/Applications/Cursor.app"
"/Applications/Zed.app"
"/Users/jakub/Applications/Home\ Manager\ Apps/kitty.app"
"${config.users.users.${config.username}.home}/Applications/Home\ Manager\ Apps/kitty.app"
"/Applications/Notion.app"
"/Applications/Slack.app"
"/Applications/Obsidian.app"
Expand Down
1 change: 1 addition & 0 deletions hosts/nyckelharpa/homebrew.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"libsodium"
"vips"
"python-setuptools"
"php"
{
name = "postgresql@14";
restart_service = "changed";
Expand Down
8 changes: 3 additions & 5 deletions hosts/organ/syncthing.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{config, ...}: let
user = "jakub";
in {
{config, ...}: {
services = {
nginx.virtualHosts.${config.networking.fqdn}.locations."/syncthing/" = {
extraConfig = "auth_request /auth;";
proxyPass = "http://localhost:8384/";
};
syncthing = {
enable = true;
user = user;
dataDir = "${config.users.users.${user}.home}/Sync";
user = config.username;
dataDir = "${config.users.users.${config.username}.home}/Sync";

# https://docs.syncthing.net/users/config.html#config-option-gui.insecureskiphostcheck
settings.gui.insecureSkipHostcheck = true;
Expand Down
2 changes: 1 addition & 1 deletion hosts/organ/users.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
age.secrets = lib._.defineSecrets ["organ-jakub-password-hash"] {};

users.users = {
jakub = {
${config.username} = {
hashedPasswordFile = config.age.secrets.organ-jakub-password-hash.path;
openssh.authorizedKeys.keys = [config.sshPublicKey];
isNormalUser = true;
Expand Down
15 changes: 6 additions & 9 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ inputs @ {
then {
fn = nix-darwin.lib.darwinSystem;
option = "darwinConfigurations";
command = "darwin-rebuild";
command = "nix run nix-darwin --";
agenixModule = agenix.darwinModules.default;
}
else {
Expand All @@ -44,27 +44,24 @@ inputs @ {
agenixModule = agenix.nixosModules.default;
};

mapHosts = builtins.mapAttrs (name: path:
mapHosts = builtins.mapAttrs (osName: path:
systemSpecifics.fn {
inherit system;
specialArgs = {inherit inputs lib pkgs self system;};
specialArgs = {inherit inputs lib pkgs self system osName;};
modules =
[
../config.nix
systemSpecifics.agenixModule
{
environment.systemPackages = [agenix.packages.${system}.default];
networking.hostName = name;
}
{networking.hostName = lib.mkDefault osName;}
path
]
++ lib._.autoloadedModules;
});

mapHomes = builtins.mapAttrs (name: path:
mapHomes = builtins.mapAttrs (homeName: path:
home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = {inherit inputs lib system;};
extraSpecialArgs = {inherit inputs lib system homeName;};
modules = [../config.nix agenix.homeManagerModules.default path] ++ lib._.autoloadedModules;
});
in {
Expand Down
24 changes: 9 additions & 15 deletions modules/common/aliases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
# common aliases shared across all systems
{
config,
homeName,
lib,
system,
...
}: {
home.shellAliases = let
username = config.home.username;
dotfiles =
osCommand =
{
"x86_64-linux" = "/persist/dotfiles";
"aarch64-linux" = "/persist/dotfiles";
"aarch64-darwin" = "$HOME/.config/dotfiles";
}
.${system};
homeConfig =
{
"x86_64-linux" = "${username}-x86";
"aarch64-linux" = "${username}-arm64";
"aarch64-darwin" = "${username}-macos";
"x86_64-linux" = "nixos-rebuild";
"aarch64-linux" = "nixos-rebuild";
"aarch64-darwin" = "darwin-rebuild";
}
.${system};
in {
Expand Down Expand Up @@ -47,8 +40,9 @@

# Utils
benchzsh = "hyperfine 'zsh -i -c exit' --warmup 1";
hm = "home-manager --flake \"${dotfiles}#${homeConfig}\"";
dots = "$EDITOR \"${dotfiles}\"";
zd = "cd \"${dotfiles}\"";
hm = "home-manager --flake \"${config.dotfilesPath}#${homeName}\"";
os = "${osCommand} --flake \"${config.dotfilesPath}\"";
dots = "$EDITOR \"${config.dotfilesPath}\"";
zd = "cd \"${config.dotfilesPath}\"";
};
}
7 changes: 6 additions & 1 deletion modules/common/nix.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [nixos/nix-darwin]
# nix with sensible defaults
{
config,
inputs,
lib,
system,
Expand All @@ -10,10 +11,14 @@
# Enable support for nix commands and flakes
settings.experimental-features = ["nix-command" "flakes"];

settings.trusted-users = ["root" "jakub"];
settings.trusted-users = ["root" config.username];

# Pinning the registry to the system pkgs on NixOS
registry.nixpkgs.flake = inputs.nixpkgs;
# Binding `<nixpkgs>` to the flake input, and similar for other flake inputs
nixPath =
lib.mapAttrsToList (name: value: "${name}=${value}")
(lib.filterAttrs (_: value: value ? _type && value._type == "flake") inputs);

# Perform garbage collection weekly to maintain low disk usage
gc = {
Expand Down
8 changes: 7 additions & 1 deletion modules/common/packages.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# [nixos/nix-darwin]
# common packages shared across all systems
{pkgs, ...}: {
{
inputs,
pkgs,
system,
...
}: {
environment.systemPackages = with pkgs; [
inputs.agenix.packages.${system}.default
alejandra
git
curl
Expand Down
4 changes: 2 additions & 2 deletions users/jakub-linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
];

home = {
username = "jakub";
homeDirectory = "/home/jakub";
username = config.username;
homeDirectory = "/home/${config.username}";
packages = with pkgs; [
home-manager
chromium
Expand Down
6 changes: 2 additions & 4 deletions users/jakub-macos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
];

home = {
username = "jakub";
homeDirectory = "/Users/jakub";
username = config.username;
homeDirectory = "/Users/${config.username}";

packages = with pkgs; [
home-manager
Expand All @@ -38,8 +38,6 @@
};

shellAliases = {
dw = "darwin-rebuild --flake \"$HOME/.config/dotfiles\"";

# Work
linear = "git checkout main && git pull && git checkout -b $(pbpaste)";
swarm = "RBENV_VERSION=$(cat $IAC_PATH/.ruby-version) $IAC_PATH/exe/swarm";
Expand Down

0 comments on commit 5e97728

Please sign in to comment.