From a00086f63df186181c254a164c77b974cc7a5c7c Mon Sep 17 00:00:00 2001 From: Skullheadx Date: Mon, 29 Jun 2026 14:38:08 -0400 Subject: DRY for username --- audio.nix | 5 ++- darwin-common.nix | 10 ++--- flake.lock | 33 +++++++++----- flake.nix | 86 +++++++++++++----------------------- hjem-darwin.nix | 20 +++++++++ hjem-linux.nix | 67 ++++++++++++++++++++++++++++ hjem.nix | 66 ---------------------------- home.nix | 96 ----------------------------------------- hosts/bear/configuration.nix | 9 +++- hosts/icon/configuration.nix | 3 +- hosts/kenosis/configuration.nix | 8 ++-- hosts/kenosis/legacy.nix | 3 +- hosts/nepsis/configuration.nix | 2 +- rebuild-darwin.sh | 1 + rebuild-linux.sh | 1 + rebuild.sh | 1 - setup-darwin.sh | 30 +++++++++++++ setup.sh | 30 ------------- x11.nix | 7 +-- 19 files changed, 202 insertions(+), 276 deletions(-) create mode 100644 hjem-darwin.nix create mode 100644 hjem-linux.nix delete mode 100644 hjem.nix delete mode 100644 home.nix create mode 100755 rebuild-darwin.sh create mode 100755 rebuild-linux.sh delete mode 100755 rebuild.sh create mode 100644 setup-darwin.sh delete mode 100644 setup.sh diff --git a/audio.nix b/audio.nix index f146189..a84bac3 100644 --- a/audio.nix +++ b/audio.nix @@ -1,6 +1,7 @@ { config, pkgs, + username, ... }: { services.pipewire = { @@ -17,7 +18,7 @@ }; }; - hjem.users.andrew = { + hjem.users.${username} = { files = { ".config/mpd/mpd.conf".source = ./dotfiles/mpd/mpd.conf; @@ -34,7 +35,7 @@ description = "Music Player Daemon"; wantedBy = ["default.target"]; serviceConfig = { - ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /home/andrew/.config/mpd/mpd.conf"; + ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /home/${username}/.config/mpd/mpd.conf"; Restart = "on-failure"; }; }; diff --git a/darwin-common.nix b/darwin-common.nix index c03c055..82b4c85 100644 --- a/darwin-common.nix +++ b/darwin-common.nix @@ -2,6 +2,7 @@ config, pkgs, inputs, + username, ... }: { imports = [ @@ -17,7 +18,6 @@ lazygit fastfetch git - senpai wget curl direnv @@ -70,10 +70,10 @@ _FXSortFoldersFirst = true; }; - # screencapture = { - # location = "/Users/andrew/Documents/Screenshots"; - # type = "jpg"; - # }; + screencapture = { + location = "/Users/${username}/Documents/Screenshots"; + type = "jpg"; + }; }; keyboard = { diff --git a/flake.lock b/flake.lock index 19f8018..0d75a46 100644 --- a/flake.lock +++ b/flake.lock @@ -59,22 +59,19 @@ }, "home-manager": { "inputs": { - "nixpkgs": [ - "nixpkgs" - ] + "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1782702263, - "narHash": "sha256-8/MG4Su7PhnynrmsVO61IeAfrK7GuUEu+E+gwbhy1QQ=", + "lastModified": 1782749631, + "narHash": "sha256-slFTUgDy0KTPA4LBAmC/9SngDq8GCPdX+ZR0yQHHN1E=", "owner": "nix-community", "repo": "home-manager", - "rev": "789a35fbdeb3c46b260096daa0b321c11be527ea", + "rev": "5d72a29fc36ac21adae6ae35568fe5ee6700850f", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "home-manager", - "type": "github" + "id": "home-manager", + "type": "indirect" } }, "mnw": { @@ -214,6 +211,22 @@ } }, "nixpkgs": { + "locked": { + "lastModified": 1782175435, + "narHash": "sha256-EMzXKmnOtBQ2MnvpiNOm7E+kOMvdPrIKaeg52Tip2Uk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "89570f24e97e614aa34aa9ab1c927b6578a43775", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1782467914, "narHash": "sha256-pGvFkM8N0xEkIIXDe5YYfbEAvHrk4IxBrjB/x8OomhE=", @@ -263,7 +276,7 @@ "my-st": "my-st", "my-surf": "my-surf", "nix-darwin": "nix-darwin", - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_2", "nvf": "nvf" } }, diff --git a/flake.nix b/flake.nix index f46e695..401f2ee 100644 --- a/flake.nix +++ b/flake.nix @@ -36,10 +36,6 @@ url = "github:notashelf/nvf"; inputs.nixpkgs.follows = "nixpkgs"; }; - home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; - }; hjem = { url = "github:feel-co/hjem"; inputs.nixpkgs.follows = "nixpkgs"; @@ -72,81 +68,61 @@ modules = [./nvf/nvf.nix]; }; in { - nixosConfigurations.nepsis = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs nvim;}; - modules = [ - hjem.nixosModules.default - ./linux-common.nix - ./hosts/nepsis/configuration.nix - ./overlays.nix - ]; - }; - nixosConfigurations.icon = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs nvim;}; - modules = [ - hjem.nixosModules.default - ./linux-common.nix - ./hosts/icon/configuration.nix - ./overlays.nix - ]; - }; - packages.${system}.nvim = nvim.neovim; packages.${system-darwin}.nvim = nvim-darwin.neovim; + nixosConfigurations = { + nepsis = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs nvim; + username = "andrew"; + }; + modules = [ + hjem.nixosModules.default + ./linux-common.nix + ./hosts/nepsis/configuration.nix + ./overlays.nix + ]; + }; + icon = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs nvim; + username = "andrew"; + }; + modules = [ + hjem.nixosModules.default + ./linux-common.nix + ./hosts/icon/configuration.nix + ./overlays.nix + ]; + }; + }; + darwinConfigurations = { kenosis = nix-darwin.lib.darwinSystem { specialArgs = { inherit inputs; nvim = nvim-darwin; + username = "andrew"; }; modules = [ ./darwin-common.nix ./hosts/kenosis/configuration.nix ./overlays.nix - home-manager.darwinModules.home-manager - { - users.users.andrew = { - home = /Users/andrew; - }; - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - }; - home-manager.users.andrew = { - imports = [./home.nix]; - home.username = "andrew"; - home.homeDirectory = /Users/andrew; - }; - } + hjem.darwinModules.default ]; }; bear = nix-darwin.lib.darwinSystem { specialArgs = { inherit inputs; nvim = nvim-darwin; + username = "andrewmontgomery"; }; modules = [ ./darwin-common.nix ./hosts/bear/configuration.nix ./overlays.nix - home-manager.darwinModules.home-manager - { - users.users.andrewmontgomery = { - home = /Users/andrewmontgomery; - }; - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - }; - home-manager.users.andrewmontgomery = { - imports = [./home.nix]; - home.username = "andrewmontgomery"; - home.homeDirectory = /Users/andrewmontgomery; - }; - } + hjem.darwinModules.default ]; }; }; diff --git a/hjem-darwin.nix b/hjem-darwin.nix new file mode 100644 index 0000000..9090d86 --- /dev/null +++ b/hjem-darwin.nix @@ -0,0 +1,20 @@ +{ + config, + pkgs, + username, + ... +}: { + imports = [ + ]; + + hjem.users.${username} = { + directory = "/home/${username}"; + files = { + ".config/senpai/senpai.scfg".source = ./dotfiles/senpai/senpai.scfg; + }; + + packages = with pkgs; [ + senpai + ]; + }; +} diff --git a/hjem-linux.nix b/hjem-linux.nix new file mode 100644 index 0000000..df49b12 --- /dev/null +++ b/hjem-linux.nix @@ -0,0 +1,67 @@ +{ + config, + pkgs, + username, + ... +}: { + imports = [ + ]; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.${username} = { + isNormalUser = true; + + extraGroups = [ + "networkmanager" + "wheel" + ]; + packages = with pkgs; []; + }; + + hjem.users.${username} = { + directory = "/home/${username}"; + files = { + ".config/surf/styles/default.css".source = ./dotfiles/surf/styles/default.css; + ".config/surf/script.js".source = ./dotfiles/surf/script.js; + + ".sfeed/sfeedrc".source = ./dotfiles/sfeed/sfeedrc; + ".config/senpai/senpai.scfg".source = ./dotfiles/senpai/senpai.scfg; + + ".config/fastfetch/config.jsonc".source = ./dotfiles/fastfetch/config.jsonc; + }; + + packages = with pkgs; [ + discord + lazygit + librewolf + btop + mpv + zathura + lf + sfeed + senpai + ]; + }; + + systemd.user.services."sfeed-update" = { + description = "Update sfeed RSS feeds"; + path = with pkgs; [ + curl + sfeed + coreutils + ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.sfeed}/bin/sfeed_update"; + }; + }; + + systemd.user.timers."sfeed-update" = { + description = "Run sfeed_update daily"; + timerConfig = { + OnCalendar = "daily"; + Persistent = true; + }; + wantedBy = ["timers.target"]; + }; +} diff --git a/hjem.nix b/hjem.nix deleted file mode 100644 index 1724568..0000000 --- a/hjem.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ - config, - pkgs, - ... -}: { - imports = [ - ]; - - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.andrew = { - isNormalUser = true; - - extraGroups = [ - "networkmanager" - "wheel" - ]; - packages = with pkgs; []; - }; - - hjem.users.andrew = { - directory = "/home/andrew"; - files = { - ".config/surf/styles/default.css".source = ./dotfiles/surf/styles/default.css; - ".config/surf/script.js".source = ./dotfiles/surf/script.js; - - ".sfeed/sfeedrc".source = ./dotfiles/sfeed/sfeedrc; - ".config/senpai/senpai.scfg".source = ./dotfiles/senpai/senpai.scfg; - - ".config/fastfetch/config.jsonc".source = ./dotfiles/fastfetch/config.jsonc; - }; - - packages = with pkgs; [ - discord - lazygit - librewolf - btop - mpv - zathura - lf - sfeed - senpai - ]; - }; - - systemd.user.services."sfeed-update" = { - description = "Update sfeed RSS feeds"; - path = with pkgs; [ - curl - sfeed - coreutils - ]; - serviceConfig = { - Type = "oneshot"; - ExecStart = "${pkgs.sfeed}/bin/sfeed_update"; - }; - }; - - systemd.user.timers."sfeed-update" = { - description = "Run sfeed_update daily"; - timerConfig = { - OnCalendar = "daily"; - Persistent = true; - }; - wantedBy = ["timers.target"]; - }; -} diff --git a/home.nix b/home.nix deleted file mode 100644 index ce48a66..0000000 --- a/home.nix +++ /dev/null @@ -1,96 +0,0 @@ -{ - config, - pkgs, - ... -}: { - # home.username = username; - # home.homeDirectory = homeDir; - # You can update Home Manager without changing this value. See - # the Home Manager release notes for a list of state version - # changes in each release. - home.stateVersion = "25.11"; - programs.home-manager.enable = true; - - programs.fzf = { - enable = true; - enableZshIntegration = true; - }; - programs.zoxide = { - enable = true; - enableZshIntegration = true; - }; - - home.file = { - ".config/senpai/senpai.scfg".source = ./dotfiles/senpai/senpai.scfg; - }; - - programs.emacs = { - enable = true; - extraConfig = '' - ;;; -*- lexical-binding: t -*- - (custom-set-variables - ;; custom-set-variables was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(custom-enabled-themes '(modus-vivendi-tinted)) - '(rcirc-default-nick "Skullheadx") - '(rcirc-server-alist - '(("irc.libera.chat" :port 6697 :channels ("#emacs" "#lobsters" "#openbsd") - :encryption tls)))) - (custom-set-faces - ;; custom-set-faces was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - ) - (global-set-key (kbd "C-c l") #'org-store-link) - (global-set-key (kbd "C-c a") #'org-agenda) - (global-set-key (kbd "C-c c") #'org-capture) - (setq org-agenda-files '("~/org")) - (setq org-todo-keywords - '((sequence - "TODO(t)" - "NEXT(n)" - "WAIT(w@)" - "|" - "DONE(d)" - "CANCELLED(c@)"))) - (setq org-capture-templates - '(("t" "Todo" entry - (file "~/org/inbox.org") - "* TODO %?\n%U"))) - (setq org-agenda-custom-commands - '(("n" "Next Actions" - todo "NEXT"))) - (setq org-log-done 'time) - - (fido-vertical-mode 1) - - ;; Nix syntax - (use-package nix-mode - :mode "\\.nix\\'") - - ;; LSP - (use-package lsp-mode - :hook (nix-mode . lsp-deferred)) - - ;; Optional UI helpers - (use-package lsp-ui - :commands lsp-ui-mode) - - ;; Formatting - (use-package apheleia - :config - (setf (alist-get 'nix-mode apheleia-mode-alist) 'alejandra) - (apheleia-global-mode +1)) - ''; - extraPackages = epkgs: - with epkgs; [ - nix-mode - lsp-mode - lsp-ui - apheleia - ]; - }; -} diff --git a/hosts/bear/configuration.nix b/hosts/bear/configuration.nix index dc96c7a..7b0eed3 100644 --- a/hosts/bear/configuration.nix +++ b/hosts/bear/configuration.nix @@ -3,15 +3,20 @@ pkgs, inputs, nvim, + username, ... }: { + imports = [ + ./../../hjem-darwin.nix + ]; + networking = { computerName = "bear"; hostName = "bear"; localHostName = "bear"; }; # Primary user for user-specific settings (dock, etc.) - system.primaryUser = "andrewmontgomery"; + system.primaryUser = username; # List packages installed in system profile. To search by name, run: # $ nix-env -qaP | grep wget environment.systemPackages = with pkgs; [ @@ -70,7 +75,7 @@ homebrew = { enable = true; - user = "andrewmontgomery"; + user = username; taps = [ ]; diff --git a/hosts/icon/configuration.nix b/hosts/icon/configuration.nix index 62c5bb8..f47a87f 100644 --- a/hosts/icon/configuration.nix +++ b/hosts/icon/configuration.nix @@ -2,6 +2,7 @@ config, pkgs, inputs, + username, ... }: { imports = [ @@ -63,7 +64,7 @@ # systemd.services.fcgiwrap.serviceConfig.ReadOnlyPaths = ["/srv/git"]; # Define a user account. Don't forget to set a password with ‘passwd’. users.users = { - andrew = { + ${username} = { isNormalUser = true; extraGroups = [ diff --git a/hosts/kenosis/configuration.nix b/hosts/kenosis/configuration.nix index be792e9..68498c5 100644 --- a/hosts/kenosis/configuration.nix +++ b/hosts/kenosis/configuration.nix @@ -3,10 +3,12 @@ pkgs, inputs, nvim, + username, ... }: { imports = [ # ./legacy.nix + ./../../hjem-darwin.nix ]; networking = { @@ -15,7 +17,7 @@ localHostName = "kenosis"; }; # Primary user for user-specific settings (dock, etc.) - system.primaryUser = "andrew"; + system.primaryUser = username; # List packages installed in system profile. To search by name, run: # $ nix-env -qaP | grep wget environment.systemPackages = with pkgs; [ @@ -48,7 +50,7 @@ homebrew = { enable = true; - user = "andrew"; + user = username; taps = [ ]; @@ -61,7 +63,7 @@ "firefox" "chatgpt" "capcut" - "docker" + "docker-desktop" "musicbrainz-picard" "gimp" ]; diff --git a/hosts/kenosis/legacy.nix b/hosts/kenosis/legacy.nix index 5d3ed93..9058952 100644 --- a/hosts/kenosis/legacy.nix +++ b/hosts/kenosis/legacy.nix @@ -1,6 +1,7 @@ { config, pkgs, + username, ... }: { environment.systemPackages = with pkgs; [ @@ -14,7 +15,7 @@ homebrew = { enable = true; - user = "andrew"; + user = username; taps = [ ]; diff --git a/hosts/nepsis/configuration.nix b/hosts/nepsis/configuration.nix index 0cf4c69..c7ef1f0 100644 --- a/hosts/nepsis/configuration.nix +++ b/hosts/nepsis/configuration.nix @@ -8,7 +8,7 @@ ./hardware-configuration.nix ./../../lockscreen.nix ./../../x11.nix - ./../../hjem.nix + ./../../hjem-linux.nix ./../../audio.nix ./../../vim.nix ]; diff --git a/rebuild-darwin.sh b/rebuild-darwin.sh new file mode 100755 index 0000000..57cebc7 --- /dev/null +++ b/rebuild-darwin.sh @@ -0,0 +1 @@ +sudo darwin-rebuild switch --flake . diff --git a/rebuild-linux.sh b/rebuild-linux.sh new file mode 100755 index 0000000..5d19064 --- /dev/null +++ b/rebuild-linux.sh @@ -0,0 +1 @@ +sudo nixos-rebuild switch --flake . diff --git a/rebuild.sh b/rebuild.sh deleted file mode 100755 index 57cebc7..0000000 --- a/rebuild.sh +++ /dev/null @@ -1 +0,0 @@ -sudo darwin-rebuild switch --flake . diff --git a/setup-darwin.sh b/setup-darwin.sh new file mode 100644 index 0000000..8c4e67c --- /dev/null +++ b/setup-darwin.sh @@ -0,0 +1,30 @@ +curl -sSf -L https://install.lix.systems/lix | sh -s -- install +. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh +nix --version + +mkdir -p ~/src +cd ~/src +git clone https://github.com/Skullheadx/dotfiles.git +cd dotfiles +git fetch origin +git checkout -b new-darwin origin/new-darwin + +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +echo >>/Users/andrew/.zprofile +echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >>/Users/andrew/.zprofile +eval "$(/opt/homebrew/bin/brew shellenv zsh)" + +sudo mkdir -p /etc/nix-darwin +sudo chown $(id -nu):$(id -ng) /etc/nix-darwin +cd /etc/nix-darwin + +# To use Nixpkgs unstable: +nix flake init -t nix-darwin/master + +sed -i '' "s/simple/$(scutil --get LocalHostName)/" flake.nix + +sudo nix run nix-darwin/master#darwin-rebuild -- switch + +zsh +cd ~/src/dotfiles +sudo darwin-rebuild switch --flake . diff --git a/setup.sh b/setup.sh deleted file mode 100644 index 8c4e67c..0000000 --- a/setup.sh +++ /dev/null @@ -1,30 +0,0 @@ -curl -sSf -L https://install.lix.systems/lix | sh -s -- install -. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh -nix --version - -mkdir -p ~/src -cd ~/src -git clone https://github.com/Skullheadx/dotfiles.git -cd dotfiles -git fetch origin -git checkout -b new-darwin origin/new-darwin - -/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -echo >>/Users/andrew/.zprofile -echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >>/Users/andrew/.zprofile -eval "$(/opt/homebrew/bin/brew shellenv zsh)" - -sudo mkdir -p /etc/nix-darwin -sudo chown $(id -nu):$(id -ng) /etc/nix-darwin -cd /etc/nix-darwin - -# To use Nixpkgs unstable: -nix flake init -t nix-darwin/master - -sed -i '' "s/simple/$(scutil --get LocalHostName)/" flake.nix - -sudo nix run nix-darwin/master#darwin-rebuild -- switch - -zsh -cd ~/src/dotfiles -sudo darwin-rebuild switch --flake . diff --git a/x11.nix b/x11.nix index 47732ac..b1483e9 100644 --- a/x11.nix +++ b/x11.nix @@ -1,6 +1,7 @@ { config, pkgs, + username, ... }: { services.displayManager.ly = { @@ -31,7 +32,7 @@ sessionCommands = '' #!/bin/sh ${pkgs.xrandr}/bin/xrandr --output DP-3 --primary --mode 2560x1440 --rate 180 --pos 0x0 --output DP-2 --mode 1920x1080 --rate 160 --pos 2560x360 - ${pkgs.feh}/bin/feh --no-fehbg --bg-fill '/home/andrew/Wallpapers/Daniel_in_the_Lions_Den_by_Briton_Riviere.jpg' + ${pkgs.feh}/bin/feh --no-fehbg --bg-fill '/home/${username}/Wallpapers/Daniel_in_the_Lions_Den_by_Briton_Riviere.jpg' ''; }; xkb = { @@ -53,7 +54,7 @@ enable = true; }; - hjem.users.andrew = { + hjem.users.${username} = { files = { ".config/sxhkd/sxhkdrc".text = builtins.readFile ( pkgs.replaceVars ./dotfiles/sxhkd/sxhkdrc { @@ -101,7 +102,7 @@ environment = { SFEED_PLUMBER = "surf"; - SFEED_URL_FILE = "/home/andrew/.local/share/sfeed/sfeed_read_url_file"; + SFEED_URL_FILE = "/home/${username}/.local/share/sfeed/sfeed_read_url_file"; }; serviceConfig = { -- cgit v1.3.1