From 5e977281063f6192267d1503377a805b19c84810 Mon Sep 17 00:00:00 2001 From: Jakub Arbet Date: Sat, 26 Oct 2024 03:14:54 +0200 Subject: [PATCH] Config updates - Add `os` alias - Add `username` config option to make the flakes easier to adapt - Make the home config name be passed down as arg --- config.nix | 19 +++++++++++++++++-- hosts/harmonium/default.nix | 7 ++++--- hosts/nyckelharpa/README.md | 12 +++++++----- hosts/nyckelharpa/default.nix | 5 +++-- hosts/nyckelharpa/homebrew.nix | 1 + hosts/organ/syncthing.nix | 8 +++----- hosts/organ/users.nix | 2 +- lib/default.nix | 15 ++++++--------- modules/common/aliases.nix | 24 +++++++++--------------- modules/common/nix.nix | 7 ++++++- modules/common/packages.nix | 8 +++++++- users/jakub-linux/default.nix | 4 ++-- users/jakub-macos/default.nix | 6 ++---- 13 files changed, 68 insertions(+), 50 deletions(-) diff --git a/config.nix b/config.nix index 87724e8..6f69a13 100644 --- a/config.nix +++ b/config.nix @@ -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"; diff --git a/hosts/harmonium/default.nix b/hosts/harmonium/default.nix index 2a7be16..8347ea2 100644 --- a/hosts/harmonium/default.nix +++ b/hosts/harmonium/default.nix @@ -1,7 +1,8 @@ { - pkgs, - lib, + config, inputs, + lib, + pkgs, ... }: { imports = @@ -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; diff --git a/hosts/nyckelharpa/README.md b/hosts/nyckelharpa/README.md index 0194808..f22f7da 100644 --- a/hosts/nyckelharpa/README.md +++ b/hosts/nyckelharpa/README.md @@ -14,14 +14,16 @@ curl -L https://nixos.org/nix/install | sh git clone git@github.com: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 ``` diff --git a/hosts/nyckelharpa/default.nix b/hosts/nyckelharpa/default.nix index 35e80b0..d370695 100644 --- a/hosts/nyckelharpa/default.nix +++ b/hosts/nyckelharpa/default.nix @@ -1,4 +1,5 @@ { + config, lib, pkgs, self, @@ -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 @@ -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" diff --git a/hosts/nyckelharpa/homebrew.nix b/hosts/nyckelharpa/homebrew.nix index e474617..2d7ae44 100644 --- a/hosts/nyckelharpa/homebrew.nix +++ b/hosts/nyckelharpa/homebrew.nix @@ -30,6 +30,7 @@ "libsodium" "vips" "python-setuptools" + "php" { name = "postgresql@14"; restart_service = "changed"; diff --git a/hosts/organ/syncthing.nix b/hosts/organ/syncthing.nix index 43e6f8e..c8f824d 100644 --- a/hosts/organ/syncthing.nix +++ b/hosts/organ/syncthing.nix @@ -1,6 +1,4 @@ -{config, ...}: let - user = "jakub"; -in { +{config, ...}: { services = { nginx.virtualHosts.${config.networking.fqdn}.locations."/syncthing/" = { extraConfig = "auth_request /auth;"; @@ -8,8 +6,8 @@ in { }; 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; diff --git a/hosts/organ/users.nix b/hosts/organ/users.nix index 46db50a..3a80776 100644 --- a/hosts/organ/users.nix +++ b/hosts/organ/users.nix @@ -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; diff --git a/lib/default.nix b/lib/default.nix index e6984bf..7b3de34 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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 { @@ -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 { diff --git a/modules/common/aliases.nix b/modules/common/aliases.nix index 6d187f3..5e78396 100644 --- a/modules/common/aliases.nix +++ b/modules/common/aliases.nix @@ -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 { @@ -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}\""; }; } diff --git a/modules/common/nix.nix b/modules/common/nix.nix index 415a297..2f3c832 100644 --- a/modules/common/nix.nix +++ b/modules/common/nix.nix @@ -1,6 +1,7 @@ # [nixos/nix-darwin] # nix with sensible defaults { + config, inputs, lib, system, @@ -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 `` 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 = { diff --git a/modules/common/packages.nix b/modules/common/packages.nix index 8a1320e..1e5fd93 100644 --- a/modules/common/packages.nix +++ b/modules/common/packages.nix @@ -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 diff --git a/users/jakub-linux/default.nix b/users/jakub-linux/default.nix index 22cca83..8cabce9 100644 --- a/users/jakub-linux/default.nix +++ b/users/jakub-linux/default.nix @@ -13,8 +13,8 @@ ]; home = { - username = "jakub"; - homeDirectory = "/home/jakub"; + username = config.username; + homeDirectory = "/home/${config.username}"; packages = with pkgs; [ home-manager chromium diff --git a/users/jakub-macos/default.nix b/users/jakub-macos/default.nix index 638755a..276b0b2 100644 --- a/users/jakub-macos/default.nix +++ b/users/jakub-macos/default.nix @@ -16,8 +16,8 @@ ]; home = { - username = "jakub"; - homeDirectory = "/Users/jakub"; + username = config.username; + homeDirectory = "/Users/${config.username}"; packages = with pkgs; [ home-manager @@ -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";