From ea01ac7fe00ac113efc99f7b9a751def8496597b Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Thu, 20 Jun 2024 11:42:31 +0300 Subject: [PATCH] Modularize code Signed-off-by: Nikolaos Karaolidis --- hosts/common/configs/persist/default.nix | 22 ++ .../persist}/impermanence.sh | 4 +- hosts/common/configs/sops/default.nix | 16 ++ hosts/common/configs/zsh/default.nix | 2 + hosts/common/default.nix | 52 +---- hosts/eirene/base/default.nix | 4 +- users/common/configs/firefox/default.nix | 158 +++++++------- users/common/configs/git/default.nix | 46 ++-- users/common/configs/gpg-agent/default.nix | 75 ++++--- users/common/configs/hyprland/default.nix | 197 ++++++++++-------- users/common/configs/kitty/default.nix | 14 +- users/common/configs/neovim/default.nix | 28 +-- users/common/configs/persist/default.nix | 28 +++ users/common/configs/sops/default.nix | 17 ++ users/common/configs/stylix/default.nix | 16 +- users/common/configs/zsh/default.nix | 30 ++- users/common/default.nix | 105 ++-------- 17 files changed, 440 insertions(+), 374 deletions(-) create mode 100644 hosts/common/configs/persist/default.nix rename hosts/common/{scripts => configs/persist}/impermanence.sh (88%) create mode 100644 hosts/common/configs/sops/default.nix create mode 100644 users/common/configs/persist/default.nix create mode 100644 users/common/configs/sops/default.nix diff --git a/hosts/common/configs/persist/default.nix b/hosts/common/configs/persist/default.nix new file mode 100644 index 0000000..7f41615 --- /dev/null +++ b/hosts/common/configs/persist/default.nix @@ -0,0 +1,22 @@ +{ inputs, lib, ... }: + +{ + imports = [ inputs.impermanence.nixosModules.impermanence ]; + + fileSystems."/persist".neededForBoot = true; + boot.initrd.postDeviceCommands = lib.mkAfter (builtins.readFile ./impermanence.sh); + + environment.persistence."/persist" = { + hideMounts = true; + directories = [ + "/etc/nixos" + "/etc/NetworkManager/system-connections" + "/var/lib/nixos" + "/var/lib/systemd/coredump" + "/var/log" + ]; + files = [ + "/etc/machine-id" + ]; + }; +} diff --git a/hosts/common/scripts/impermanence.sh b/hosts/common/configs/persist/impermanence.sh similarity index 88% rename from hosts/common/scripts/impermanence.sh rename to hosts/common/configs/persist/impermanence.sh index 525b32f..abaf8da 100644 --- a/hosts/common/scripts/impermanence.sh +++ b/hosts/common/configs/persist/impermanence.sh @@ -1,5 +1,3 @@ -#!/bin/sh - delete_subvolume_recursively() { IFS=$'\n' for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do @@ -17,7 +15,7 @@ if [[ -e /mnt/btrfs/root ]]; then mv /mnt/btrfs/root "/mnt/btrfs/root.bak/$timestamp" fi -find /mnt/btrfs/root.bak/ -maxdepth 1 -mtime +30 | while IFS= read -r i; do +find /mnt/btrfs/root.bak/ -maxdepth 1 -mtime +14 | while IFS= read -r i; do delete_subvolume_recursively "$i" done diff --git a/hosts/common/configs/sops/default.nix b/hosts/common/configs/sops/default.nix new file mode 100644 index 0000000..ff4d06c --- /dev/null +++ b/hosts/common/configs/sops/default.nix @@ -0,0 +1,16 @@ +{ inputs, pkgs, ... }: + +{ + imports = [ inputs.sops-nix.nixosModules.sops ]; + + environment = { + persistence."/persist".files = [ "/etc/ssh/ssh_host_ed25519_key" ]; + systemPackages = with pkgs; [ sops ]; + }; + + sops.age = { + generateKey = true; + sshKeyPaths = [ "/persist/etc/ssh/ssh_host_ed25519_key" ]; + keyFile = "/var/lib/sops-nix/key.txt"; + }; +} diff --git a/hosts/common/configs/zsh/default.nix b/hosts/common/configs/zsh/default.nix index 6c1512c..1c7d3a5 100644 --- a/hosts/common/configs/zsh/default.nix +++ b/hosts/common/configs/zsh/default.nix @@ -3,4 +3,6 @@ enable = true; histFile = "/var/lib/zsh/history"; }; + + environment.persistence."/persist".directories = [ "/var/lib/zsh" ]; } diff --git a/hosts/common/default.nix b/hosts/common/default.nix index 1454154..3057e71 100644 --- a/hosts/common/default.nix +++ b/hosts/common/default.nix @@ -2,8 +2,9 @@ { imports = [ - inputs.impermanence.nixosModules.impermanence - inputs.sops-nix.nixosModules.sops + ./configs/persist + ./configs/sops + ./configs/pipewire ./configs/zsh ./configs/neovim @@ -14,8 +15,6 @@ ./configs/gpg-agent ]; - fileSystems."/persist".neededForBoot = true; - boot = { loader = { systemd-boot.enable = true; @@ -23,46 +22,23 @@ efi.canTouchEfiVariables = true; }; - initrd = { - verbose = false; - postDeviceCommands = lib.mkAfter (builtins.readFile ./scripts/impermanence.sh); - }; - kernelPackages = pkgs.linuxPackages_latest; supportedFilesystems = [ "btrfs" "ntfs" ]; kernelParams = [ "loglevel=3" "quiet" ]; + initrd.verbose = false; consoleLogLevel = 0; }; - environment = { - persistence."/persist" = { - hideMounts = true; - directories = [ - "/etc/nixos" - "/etc/NetworkManager/system-connections" - "/var/lib/nixos" - "/var/lib/systemd/coredump" - "/var/lib/zsh" - "/var/log" - ]; - files = [ - "/etc/ssh/ssh_host_ed25519_key" - "/etc/machine-id" - ]; - }; - - systemPackages = with pkgs; [ - tree - ranger - btop - fastfetch - sops - ]; - }; - networking.networkmanager.enable = true; i18n.defaultLocale = "en_US.UTF-8"; + environment.systemPackages = with pkgs; [ + tree + ranger + btop + fastfetch + ]; + users = { mutableUsers = false; defaultUserShell = pkgs.zsh; @@ -72,12 +48,6 @@ Defaults lecture = never ''; - sops.age = { - generateKey = true; - sshKeyPaths = [ "/persist/etc/ssh/ssh_host_ed25519_key" ]; - keyFile = "/var/lib/sops-nix/key.txt"; - }; - system = { autoUpgrade = { enable = true; diff --git a/hosts/eirene/base/default.nix b/hosts/eirene/base/default.nix index 1f306b9..7151bc4 100644 --- a/hosts/eirene/base/default.nix +++ b/hosts/eirene/base/default.nix @@ -13,9 +13,7 @@ # https://github.com/NixOS/nixos-hardware/tree/master/lenovo/legion/16achg6 hardware = { - cpu.amd = { - updateMicrocode = true; - }; + cpu.amd.updateMicrocode = true; nvidia = { modesetting.enable = true; diff --git a/users/common/configs/firefox/default.nix b/users/common/configs/firefox/default.nix index a3dc3eb..1b11c75 100644 --- a/users/common/configs/firefox/default.nix +++ b/users/common/configs/firefox/default.nix @@ -1,88 +1,98 @@ -{ pkgs, ... }: +{ config, lib, pkgs, ... }: { - programs.firefox = { - enable = true; - policies = { - DisableTelemetry = true; - DisableFirefoxStudies = true; - DontCheckDefaultBrowser = true; - DisablePocket = true; - DefaultDownloadDirectory = "\${HOME}/Downloads"; - OfferToSaveLogins = false; - AutofillAddressEnabled = false; - AutofillCreditCardEnabled = false; - Preferences = { - "browser.aboutConfig.showWarning" = false; - "browser.contentblocking.category" = "strict"; - "browser.download.useDownloadDir" = false; - "browser.newtabpage.activity-stream.feeds.section.topstories" = false; - "browser.newtabpage.activity-stream.showSponsored" = false; - "browser.newtabpage.activity-stream.showSponsoredTopSites" = false; - "browser.toolbars.bookmarks.visibility" = true; - "browser.sessionstore.restore_on_demand" = true; - "browser.sessionstore.restore_pinned_tabs_on_demand" = false; - "browser.translations.automaticallyPopup" = false; - }; - }; - profiles.nick = { - search = { - default = "DuckDuckGo"; - privateDefault = "DuckDuckGo"; - order = [ - "DuckDuckGo" - "Google" - "Wikipedia (en)" - "Nix Packages" - "Nix Options" - "Home Manager Options" - ]; - force = true; - engines = { - "Google".metaData.alias = "@g"; - "DuckDuckGo".metaData.alias = "@d"; - "Wikipedia (en)".metaData.alias = "@w"; + home-manager = { + sharedModules = [{ + programs.firefox = { + enable = true; - "Nix Packages" = { - urls = [{ - template = "https://search.nixos.org/packages"; - params = [ - { name = "type"; value = "packages"; } - { name = "query"; value = "{searchTerms}"; } - ]; - }]; - - icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; - definedAliases = [ "@np" ]; + policies = { + DisableTelemetry = true; + DisableFirefoxStudies = true; + DontCheckDefaultBrowser = true; + DisablePocket = true; + DefaultDownloadDirectory = "\${HOME}/Downloads"; + OfferToSaveLogins = false; + AutofillAddressEnabled = false; + AutofillCreditCardEnabled = false; + Preferences = { + "browser.aboutConfig.showWarning" = false; + "browser.contentblocking.category" = "strict"; + "browser.download.useDownloadDir" = false; + "browser.newtabpage.activity-stream.feeds.section.topstories" = false; + "browser.newtabpage.activity-stream.showSponsored" = false; + "browser.newtabpage.activity-stream.showSponsoredTopSites" = false; + "browser.toolbars.bookmarks.visibility" = true; + "browser.sessionstore.restore_on_demand" = true; + "browser.sessionstore.restore_pinned_tabs_on_demand" = false; + "browser.translations.automaticallyPopup" = false; }; + }; - "Nix Options" = { - urls = [{ - template = "https://search.nixos.org/options"; - params = [ - { name = "type"; value = "options"; } - { name = "query"; value = "{searchTerms}"; } - ]; - }]; + profiles.nick = { + search = { + default = "DuckDuckGo"; + privateDefault = "DuckDuckGo"; + order = [ + "DuckDuckGo" + "Google" + "Wikipedia (en)" + "Nix Packages" + "Nix Options" + "Home Manager Options" + ]; + force = true; + engines = { + "Google".metaData.alias = "@g"; + "DuckDuckGo".metaData.alias = "@d"; + "Wikipedia (en)".metaData.alias = "@w"; - icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; - definedAliases = [ "@no" ]; - }; + "Nix Packages" = { + urls = [{ + template = "https://search.nixos.org/packages"; + params = [ + { name = "type"; value = "packages"; } + { name = "query"; value = "{searchTerms}"; } + ]; + }]; - "Home Manager Options" = { - urls = [{ - template = "https://home-manager-options.extranix.com/"; - params = [ - { name = "query"; value = "{searchTerms}"; } - ]; - }]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = [ "@np" ]; + }; - icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; - definedAliases = [ "@nh" ]; + "Nix Options" = { + urls = [{ + template = "https://search.nixos.org/options"; + params = [ + { name = "type"; value = "options"; } + { name = "query"; value = "{searchTerms}"; } + ]; + }]; + + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = [ "@no" ]; + }; + + "Home Manager Options" = { + urls = [{ + template = "https://home-manager-options.extranix.com/"; + params = [ + { name = "query"; value = "{searchTerms}"; } + ]; + }]; + + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = [ "@nh" ]; + }; + }; }; }; }; - }; + }]; + + users = lib.attrsets.mapAttrs (user: config: ({ + home.persistence."/persist${config.home}".directories = [ ".mozilla" ]; + })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); }; } diff --git a/users/common/configs/git/default.nix b/users/common/configs/git/default.nix index a601f38..013a18f 100644 --- a/users/common/configs/git/default.nix +++ b/users/common/configs/git/default.nix @@ -1,23 +1,35 @@ -{ pkgs, ... }: +{ config, lib, pkgs, ... }: { - programs.git = { - enable = true; - lfs.enable = true; - signing = { - signByDefault = true; - key = null; - }; - extraConfig.credential.helper = "store"; - hooks = { - commit-msg = pkgs.writeScript "git-commit-msg" '' - #!${pkgs.runtimeShell} + home-manager = { + sharedModules = [{ + programs.git = { + enable = true; + lfs.enable = true; + signing = { + signByDefault = true; + key = null; + }; + extraConfig.credential.helper = "store"; + hooks = let + commit-msg-hook = pkgs.writeShellScriptBin "git-commit-msg" '' + git interpret-trailers --if-exists doNothing --trailer \ + "Signed-off-by: $(git config user.name) <$(git config user.email)>" \ + --in-place "$1" + ''; + in + { + commit-msg = "${commit-msg-hook}/bin/git-commit-msg"; + }; + }; + }]; - git interpret-trailers --if-exists doNothing --trailer \ - "Signed-off-by: $(git config user.name) <$(git config user.email)>" \ - --in-place "$1" - ''; - }; + users = lib.attrsets.mapAttrs (user: config: ({ + programs.git = { + userName = config.fullName; + userEmail = config.email; + }; + })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); }; } diff --git a/users/common/configs/gpg-agent/default.nix b/users/common/configs/gpg-agent/default.nix index 99c4d82..9303ebc 100644 --- a/users/common/configs/gpg-agent/default.nix +++ b/users/common/configs/gpg-agent/default.nix @@ -1,43 +1,52 @@ -{ pkgs, ... }: +{ config, lib, pkgs, ... }: { - services.gpg-agent = { - enable = true; - defaultCacheTtl = 31536000; - maxCacheTtl = 31536000; - }; + home-manager = { + sharedModules = [{ + services.gpg-agent = { + enable = true; + defaultCacheTtl = 31536000; + maxCacheTtl = 31536000; + }; - systemd.user.services.gpg-agent-import = { - Unit = { - Description = "Auto-import GPG keys"; - Requires = [ "sops-nix.service" "gpg-agent.socket" ]; - After = [ "sops-nix.service" "gpg-agent.socket" ]; - }; + systemd.user.services.gpg-agent-import = let + init = pkgs.writeShellScriptBin "import-gpg-keys" '' + for keyfile in "$HOME"/.config/sops-nix/secrets/gpg-agent/*.key; do + passfile="''${keyfile%.key}.pass" - Service = { - Type = "oneshot"; - ExecStart = pkgs.writeScript "import-gpg-keys" '' - #!${pkgs.runtimeShell} + if [ -f "$passfile" ]; then + gpg --batch --yes --pinentry-mode loopback --passphrase-file "$passfile" --import "$keyfile" + else + gpg --batch --yes --import "$keyfile" + fi - for keyfile in "$HOME"/.config/sops-nix/secrets/gpg-agent/*.key; do - passfile="''${keyfile%.key}.pass" - - if [ -f "$passfile" ]; then - gpg --batch --yes --pinentry-mode loopback --passphrase-file "$passfile" --import "$keyfile" - else - gpg --batch --yes --import "$keyfile" - fi - - gpg --with-colons --import-options show-only --import "$keyfile" | grep '^fpr' | cut -d: -f10 | while read -r KEY_ID; do - echo "$KEY_ID:6:" >> "$HOME"/.gnupg/otrust.txt + gpg --with-colons --import-options show-only --import "$keyfile" | grep '^fpr' | cut -d: -f10 | while read -r KEY_ID; do + echo "$KEY_ID:6:" >> "$HOME"/.gnupg/otrust.txt + done done - done - gpg --import-ownertrust "$HOME"/.gnupg/otrust.txt - rm "$HOME"/.gnupg/otrust.txt - ''; - }; + gpg --import-ownertrust "$HOME"/.gnupg/otrust.txt + rm "$HOME"/.gnupg/otrust.txt + ''; + in + { + Unit = { + Description = "Auto-import GPG keys"; + Requires = [ "sops-nix.service" "gpg-agent.socket" ]; + After = [ "sops-nix.service" "gpg-agent.socket" ]; + }; - Install = { WantedBy = [ "default.target" ]; }; + Service = { + Type = "oneshot"; + ExecStart = "${init}/bin/import-gpg-keys"; + }; + + Install = { WantedBy = [ "default.target" ]; }; + }; + }]; + + users = lib.attrsets.mapAttrs (user: config: ({ + systemd.user.tmpfiles.rules = [ "d ${config.home}/.gnupg 0700 ${user} users -" ]; + })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); }; } diff --git a/users/common/configs/hyprland/default.nix b/users/common/configs/hyprland/default.nix index 69acdb1..2b8b688 100644 --- a/users/common/configs/hyprland/default.nix +++ b/users/common/configs/hyprland/default.nix @@ -1,99 +1,132 @@ +{ config, lib, pkgs, ... }: + { - wayland.windowManager.hyprland = { - enable = true; - settings = { - "$mod" = "SUPER"; - "$term" = "kitty"; + programs.hyprland.enable = true; - bind = [ - "$mod, Return, exec, $term" - "$mod, r, exec, rofi -show drun" - "$mod, b, exec, firefox" + environment.sessionVariables.NIXOS_OZONE_WL = "1"; - "$mod, 1, workspace, 1" - "$mod, 2, workspace, 2" - "$mod, 3, workspace, 3" - "$mod, 4, workspace, 4" - "$mod, 5, workspace, 5" - "$mod, 6, workspace, 6" - "$mod, 7, workspace, 7" - "$mod, 8, workspace, 8" - "$mod, 9, workspace, 9" - "$mod, 0, workspace, 10" + home-manager = { + sharedModules = [{ + wayland.windowManager.hyprland = { + enable = true; + settings = { + "$mod" = "SUPER"; + "$term" = "kitty"; - "$mod_SHIFT, 1, movetoworkspacesilent, 1" - "$mod_SHIFT, 2, movetoworkspacesilent, 2" - "$mod_SHIFT, 3, movetoworkspacesilent, 3" - "$mod_SHIFT, 4, movetoworkspacesilent, 4" - "$mod_SHIFT, 5, movetoworkspacesilent, 5" - "$mod_SHIFT, 6, movetoworkspacesilent, 6" - "$mod_SHIFT, 7, movetoworkspacesilent, 7" - "$mod_SHIFT, 8, movetoworkspacesilent, 8" - "$mod_SHIFT, 9, movetoworkspacesilent, 9" - "$mod_SHIFT, 0, movetoworkspacesilent, 10" + bind = [ + "$mod, Return, exec, $term" + "$mod, r, exec, rofi -show drun" + "$mod, b, exec, firefox" - "$mod_CTRL, Space, workspaceopt, allfloat" + "$mod, 1, workspace, 1" + "$mod, 2, workspace, 2" + "$mod, 3, workspace, 3" + "$mod, 4, workspace, 4" + "$mod, 5, workspace, 5" + "$mod, 6, workspace, 6" + "$mod, 7, workspace, 7" + "$mod, 8, workspace, 8" + "$mod, 9, workspace, 9" + "$mod, 0, workspace, 10" - "$mod, left, movefocus, l" - "$mod, h, movefocus, l" - "$mod, down, movefocus, d" - "$mod, j, movefocus, d" - "$mod, up, movefocus, u" - "$mod, k, movefocus, u" - "$mod, right, movefocus, r" - "$mod, l, movefocus, r" + "$mod_SHIFT, 1, movetoworkspacesilent, 1" + "$mod_SHIFT, 2, movetoworkspacesilent, 2" + "$mod_SHIFT, 3, movetoworkspacesilent, 3" + "$mod_SHIFT, 4, movetoworkspacesilent, 4" + "$mod_SHIFT, 5, movetoworkspacesilent, 5" + "$mod_SHIFT, 6, movetoworkspacesilent, 6" + "$mod_SHIFT, 7, movetoworkspacesilent, 7" + "$mod_SHIFT, 8, movetoworkspacesilent, 8" + "$mod_SHIFT, 9, movetoworkspacesilent, 9" + "$mod_SHIFT, 0, movetoworkspacesilent, 10" - "$mod_SHIFT, left, movewindow, l" - "$mod_SHIFT, h, movewindow, l" - "$mod_SHIFT, down, movewindow, d" - "$mod_SHIFT, j, movewindow, d" - "$mod_SHIFT, up, movewindow, u" - "$mod_SHIFT, k, movewindow, u" - "$mod_SHIFT, right, movewindow, r" - "$mod_SHIFT, l, movewindow, r" + "$mod_CTRL, Space, workspaceopt, allfloat" - "$mod_CTRL, left, resizeactive, -20 0" - "$mod_CTRL, h, resizeactive, -20 0" - "$mod_CTRL, down, resizeactive, 0 20" - "$mod_CTRL, j, resizeactive, 0 20" - "$mod_CTRL, up, resizeactive, 0 -20" - "$mod_CTRL, k, resizeactive, 0 -20" - "$mod_CTRL, right, resizeactive, 20 0" - "$mod_CTRL, l, resizeactive, 20 0" + "$mod, left, movefocus, l" + "$mod, h, movefocus, l" + "$mod, down, movefocus, d" + "$mod, j, movefocus, d" + "$mod, up, movefocus, u" + "$mod, k, movefocus, u" + "$mod, right, movefocus, r" + "$mod, l, movefocus, r" - "$mod, Tab, cyclenext" - "$mod, Tab, bringactivetotop" - "$mod_SHIFT, Tab, cyclenext, prev" - "$mod_SHIFT, Tab, bringactivetotop" + "$mod_SHIFT, left, movewindow, l" + "$mod_SHIFT, h, movewindow, l" + "$mod_SHIFT, down, movewindow, d" + "$mod_SHIFT, j, movewindow, d" + "$mod_SHIFT, up, movewindow, u" + "$mod_SHIFT, k, movewindow, u" + "$mod_SHIFT, right, movewindow, r" + "$mod_SHIFT, l, movewindow, r" - "$mod, f, fullscreen, 0" - "$mod, p, pin" - "$mod, Space, togglefloating" - "$mod, Space, centerwindow" - "$mod, q, killactive" + "$mod_CTRL, left, resizeactive, -20 0" + "$mod_CTRL, h, resizeactive, -20 0" + "$mod_CTRL, down, resizeactive, 0 20" + "$mod_CTRL, j, resizeactive, 0 20" + "$mod_CTRL, up, resizeactive, 0 -20" + "$mod_CTRL, k, resizeactive, 0 -20" + "$mod_CTRL, right, resizeactive, 20 0" + "$mod_CTRL, l, resizeactive, 20 0" - "CTRL_ALT, Delete, exit" - ]; + "$mod, Tab, cyclenext" + "$mod, Tab, bringactivetotop" + "$mod_SHIFT, Tab, cyclenext, prev" + "$mod_SHIFT, Tab, bringactivetotop" - bindm = [ - "$mod, mouse:272, movewindow" - "$mod, mouse:273, resizewindow" - ]; + "$mod, f, fullscreen, 0" + "$mod, p, pin" + "$mod, Space, togglefloating" + "$mod, Space, centerwindow" + "$mod, q, killactive" - input = { - "accel_profile" = "flat"; + "CTRL_ALT, Delete, exit" + ]; + + bindm = [ + "$mod, mouse:272, movewindow" + "$mod, mouse:273, resizewindow" + ]; + + input = { + "accel_profile" = "flat"; + }; + + misc = { + "disable_hyprland_logo" = true; + "disable_splash_rendering" = true; + }; + }; }; - misc = { - "disable_hyprland_logo" = true; - "disable_splash_rendering" = true; - }; - }; + programs.zsh.loginExtra = '' + if [ -z "''${WAYLAND_DISPLAY}" ] && [ ! -z "''${XDG_VTNR}" ] && [ "''${XDG_VTNR}" -eq 1 ]; then + ${pkgs.hyprland}/bin/hyprland &> /tmp/hyprland.log + fi + ''; + + home.packages = with pkgs; [ + swww + rofi-wayland + pavucontrol + ]; + }]; + + users = lib.attrsets.mapAttrs (user: config: ( + let + init = pkgs.writeShellScriptBin "hyprland-init" '' + ${pkgs.swww}/bin/swww-daemon &> /tmp/swww.log & + + while ! ${pkgs.swww}/bin/swww query &> /dev/null; do + sleep 0.1 + done + + ${pkgs.swww}/bin/swww img ${config.wallpaper} + ''; + in + { + wayland.windowManager.hyprland.settings.exec-once = "${init}/bin/hyprland-init"; + } + )) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); }; - - programs.zsh.loginExtra = '' - if [ -z "''${WAYLAND_DISPLAY}" ] && [ ! -z "''${XDG_VTNR}" ] && [ "''${XDG_VTNR}" -eq 1 ]; then - hyprland &> /tmp/hyprland.log - fi - ''; } diff --git a/users/common/configs/kitty/default.nix b/users/common/configs/kitty/default.nix index 2f796d2..3543875 100644 --- a/users/common/configs/kitty/default.nix +++ b/users/common/configs/kitty/default.nix @@ -1,8 +1,10 @@ { - programs.kitty = { - enable = true; - extraConfig = '' - confirm_os_window_close 0 - ''; - }; + home-manager.sharedModules = [{ + programs.kitty = { + enable = true; + extraConfig = '' + confirm_os_window_close 0 + ''; + }; + }]; } diff --git a/users/common/configs/neovim/default.nix b/users/common/configs/neovim/default.nix index 74ddc61..23a70c3 100644 --- a/users/common/configs/neovim/default.nix +++ b/users/common/configs/neovim/default.nix @@ -1,16 +1,18 @@ { - programs.neovim = { - enable = true; - defaultEditor = true; - viAlias = true; - vimAlias = true; - vimdiffAlias = true; - extraConfig = '' - set tabstop=2 - set shiftwidth=2 - set expandtab - set smartindent - ''; - }; + home-manager.sharedModules = [{ + programs.neovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + extraConfig = '' + set tabstop=2 + set shiftwidth=2 + set expandtab + set smartindent + ''; + }; + }]; } diff --git a/users/common/configs/persist/default.nix b/users/common/configs/persist/default.nix new file mode 100644 index 0000000..62877ce --- /dev/null +++ b/users/common/configs/persist/default.nix @@ -0,0 +1,28 @@ +{ config, inputs, lib, ... }: + +{ + programs.fuse.userAllowOther = true; + + systemd.tmpfiles.rules = [ "d /persist/home 0755 root root -" ] ++ + lib.attrsets.mapAttrsToList (user: config: "d /persist${config.home} 0700 ${user} users -") + (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); + + home-manager = { + sharedModules = [{ imports = [ inputs.impermanence.nixosModules.home-manager.impermanence ]; }]; + users = lib.attrsets.mapAttrs (user: config: ({ + home.persistence."/persist${config.home}" = { + allowOther = true; + directories = [ + "Documents" + "Downloads" + "Music" + "Pictures" + "Videos" + "Templates" + "VMs" + "git" + ]; + }; + })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); + }; +} diff --git a/users/common/configs/sops/default.nix b/users/common/configs/sops/default.nix new file mode 100644 index 0000000..12bc07f --- /dev/null +++ b/users/common/configs/sops/default.nix @@ -0,0 +1,17 @@ +{ config, inputs, lib, ... }: + +let + sopsKeyPath = ".config/sops-nix/key.txt"; +in +{ + environment.sessionVariables.SOPS_AGE_KEY_FILE = "$HOME/${sopsKeyPath}"; + + home-manager = { + sharedModules = [{ imports = [ inputs.sops-nix.homeManagerModules.sops ]; }]; + + users = lib.attrsets.mapAttrs (user: config: ({ + home.persistence."/persist${config.home}".files = [ sopsKeyPath ]; + sops.age.keyFile = "/persist${config.home}/${sopsKeyPath}"; + })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); + }; +} diff --git a/users/common/configs/stylix/default.nix b/users/common/configs/stylix/default.nix index 92fe8a1..d47d730 100644 --- a/users/common/configs/stylix/default.nix +++ b/users/common/configs/stylix/default.nix @@ -1,3 +1,17 @@ +{ config, inputs, lib, ... }: + { - stylix.enable = true; + home-manager = { + sharedModules = [{ + imports = [ inputs.stylix.homeManagerModules.stylix ]; + stylix.enable = true; + }]; + + users = lib.attrsets.mapAttrs (user: config: ({ + stylix = { + image = config.wallpaper; + base16Scheme = config.base16Scheme; + }; + })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); + }; } diff --git a/users/common/configs/zsh/default.nix b/users/common/configs/zsh/default.nix index 05ee43b..35d084a 100644 --- a/users/common/configs/zsh/default.nix +++ b/users/common/configs/zsh/default.nix @@ -1,13 +1,23 @@ +{ config, lib, ... }: + { - programs.zsh = { - enable = true; - autocd = true; - history = { - path = "$HOME/.local/share/zsh/history"; - expireDuplicatesFirst = true; - }; - historySubstringSearch.enable = true; - autosuggestion.enable = true; - syntaxHighlighting.enable = true; + home-manager = { + sharedModules = [{ + programs.zsh = { + enable = true; + autocd = true; + history = { + path = "$HOME/.local/share/zsh/history"; + expireDuplicatesFirst = true; + }; + historySubstringSearch.enable = true; + autosuggestion.enable = true; + syntaxHighlighting.enable = true; + }; + }]; + + users = lib.attrsets.mapAttrs (user: config: ({ + home.persistence."/persist${config.home}".directories = [ ".local/share/zsh" ]; + })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); }; } diff --git a/users/common/default.nix b/users/common/default.nix index 7201716..a4a0c59 100644 --- a/users/common/default.nix +++ b/users/common/default.nix @@ -1,108 +1,31 @@ { config, inputs, lib, pkgs, ... }: -let - normalUsers = lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users; -in { imports = [ inputs.home-manager.nixosModules.default ./extra.nix + + ./configs/persist + ./configs/sops + + ./configs/firefox + ./configs/git + ./configs/gpg-agent + ./configs/hyprland + ./configs/kitty + ./configs/neovim + ./configs/stylix + ./configs/zsh ]; - programs = { - hyprland.enable = true; - fuse.userAllowOther = true; - dconf.enable = true; - }; - - environment.sessionVariables = { - NIXOS_OZONE_WL = "1"; - SOPS_AGE_KEY_FILE = "$HOME/.config/sops-nix/key.txt"; - }; - home-manager = { extraSpecialArgs = { inherit inputs; }; backupFileExtension = "bak"; - sharedModules = [{ - imports = [ - inputs.impermanence.nixosModules.home-manager.impermanence - inputs.sops-nix.homeManagerModules.sops - inputs.stylix.homeManagerModules.stylix - ./configs/stylix - ./configs/hyprland - ./configs/git - ./configs/zsh - ./configs/neovim - ./configs/kitty - ./configs/firefox - ./configs/gpg-agent - ]; - - home = { - packages = with pkgs; [ - rofi-wayland - swww - pavucontrol - ]; - - stateVersion = "24.05"; - }; - + home.stateVersion = "24.05"; systemd.user.startServices = "sd-switch"; }]; - - users = lib.attrsets.mapAttrs' (user: config: lib.attrsets.nameValuePair - (user) - (let - init = pkgs.pkgs.writeShellScriptBin "hyprland-init" '' - ${pkgs.swww}/bin/swww-daemon &> /tmp/swww.log & - - while ! swww query &> /dev/null; do - sleep 0.1 - done - - ${pkgs.swww}/bin/swww img ${config.wallpaper} - ''; - in - { - home.persistence."/persist${config.home}" = { - directories = [ - "Documents" - "Downloads" - "Music" - "Pictures" - "Videos" - "Templates" - "VMs" - "git" - ".mozilla" - ".local/share/zsh" - ]; - files = [ - ".config/sops-nix/key.txt" - ]; - allowOther = true; - }; - - sops.age.keyFile = "/persist${config.home}/.config/sops-nix/key.txt"; - - programs.git = { - userName = config.fullName; - userEmail = config.email; - }; - - stylix = { - image = config.wallpaper; - base16Scheme = config.base16Scheme; - }; - - wayland.windowManager.hyprland.settings.exec-once = "${init}/bin/hyprland-init"; - }) - ) normalUsers; }; - systemd.tmpfiles.rules = [ "d /persist/home/ 0755 root root -" ] ++ - lib.attrsets.mapAttrsToList ( user: config: "d /persist${config.home} 0700 ${user} users -" ) normalUsers ++ - lib.attrsets.mapAttrsToList ( user: config: "d ${config.home}/.gnupg 0700 ${user} users -" ) normalUsers; + programs.dconf.enable = true; }