From ce37f320c213d55449a23b777dd5f8fe294186be Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Fri, 21 Jun 2024 00:08:02 +0300 Subject: [PATCH] Clean up common user modules Signed-off-by: Nikolaos Karaolidis --- hosts/common/default.nix | 1 - users/common/configs/firefox/default.nix | 97 ------------- users/common/configs/git/default.nix | 34 ----- users/common/configs/hyprland/default.nix | 132 ------------------ users/common/configs/persist/default.nix | 48 ++++--- users/common/configs/sops/default.nix | 20 +-- users/common/configs/stylix/default.nix | 17 --- users/common/configs/vscode/default.nix | 68 --------- users/common/configs/vscode/langs/nix.nix | 23 --- users/common/configs/zsh/default.nix | 23 --- users/common/default.nix | 13 +- users/common/{extra.nix => options.nix} | 3 +- users/configs/firefox/default.nix | 93 ++++++++++++ users/configs/git/default.nix | 26 ++++ .../configs/gpg-agent/default.nix | 35 +++-- users/configs/hyprland/default.nix | 126 +++++++++++++++++ users/{common => }/configs/kitty/default.nix | 6 +- users/{common => }/configs/neovim/default.nix | 6 +- users/configs/stylix/default.nix | 13 ++ users/configs/vscode/default.nix | 64 +++++++++ users/configs/vscode/langs/nix.nix | 19 +++ users/configs/zsh/default.nix | 19 +++ users/nick/default.nix | 36 ++--- users/nick/nogui.nix | 44 ++++++ 24 files changed, 476 insertions(+), 490 deletions(-) delete mode 100644 users/common/configs/firefox/default.nix delete mode 100644 users/common/configs/git/default.nix delete mode 100644 users/common/configs/hyprland/default.nix delete mode 100644 users/common/configs/stylix/default.nix delete mode 100644 users/common/configs/vscode/default.nix delete mode 100644 users/common/configs/vscode/langs/nix.nix delete mode 100644 users/common/configs/zsh/default.nix rename users/common/{extra.nix => options.nix} (99%) create mode 100644 users/configs/firefox/default.nix create mode 100644 users/configs/git/default.nix rename users/{common => }/configs/gpg-agent/default.nix (55%) create mode 100644 users/configs/hyprland/default.nix rename users/{common => }/configs/kitty/default.nix (54%) rename users/{common => }/configs/neovim/default.nix (73%) create mode 100644 users/configs/stylix/default.nix create mode 100644 users/configs/vscode/default.nix create mode 100644 users/configs/vscode/langs/nix.nix create mode 100644 users/configs/zsh/default.nix create mode 100644 users/nick/nogui.nix diff --git a/hosts/common/default.nix b/hosts/common/default.nix index a2dfa5a..159d958 100644 --- a/hosts/common/default.nix +++ b/hosts/common/default.nix @@ -4,7 +4,6 @@ imports = [ ./configs/persist ./configs/sops - ./configs/pipewire ./configs/zsh ./configs/neovim diff --git a/users/common/configs/firefox/default.nix b/users/common/configs/firefox/default.nix deleted file mode 100644 index c9cddba..0000000 --- a/users/common/configs/firefox/default.nix +++ /dev/null @@ -1,97 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - home-manager = { - sharedModules = [{ - 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"; - - "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" ]; - }; - - "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 deleted file mode 100644 index 80e6f02..0000000 --- a/users/common/configs/git/default.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - 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"; - }; - }; - }]; - - 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/hyprland/default.nix b/users/common/configs/hyprland/default.nix deleted file mode 100644 index 8023913..0000000 --- a/users/common/configs/hyprland/default.nix +++ /dev/null @@ -1,132 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - programs.hyprland.enable = true; - - environment.sessionVariables.NIXOS_OZONE_WL = "1"; - - home-manager = { - sharedModules = [{ - wayland.windowManager.hyprland = { - enable = true; - settings = { - "$mod" = "SUPER"; - "$term" = "kitty"; - - bind = [ - "$mod, Return, exec, $term" - "$mod, r, exec, rofi -show drun" - "$mod, b, exec, firefox" - - "$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_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_CTRL, Space, workspaceopt, allfloat" - - "$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, 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, 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, Tab, cyclenext" - "$mod, Tab, bringactivetotop" - "$mod_SHIFT, Tab, cyclenext, prev" - "$mod_SHIFT, Tab, bringactivetotop" - - "$mod, f, fullscreen, 0" - "$mod, p, pin" - "$mod, Space, togglefloating" - "$mod, Space, centerwindow" - "$mod, q, killactive" - - "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; - }; - }; - }; - - programs.zsh.loginExtra = lib.mkAfter '' - 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); - }; -} diff --git a/users/common/configs/persist/default.nix b/users/common/configs/persist/default.nix index 62877ce..daf8a8f 100644 --- a/users/common/configs/persist/default.nix +++ b/users/common/configs/persist/default.nix @@ -1,28 +1,30 @@ { config, inputs, lib, ... }: -{ - programs.fuse.userAllowOther = true; +let + users = lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users; +in { + programs.fuse.userAllowOther = lib.mkIf (users != [ ]) 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); + systemd.tmpfiles.rules = lib.mkIf (users != [ ]) ( + [ "d /persist/home 0755 root root -" ] ++ + lib.attrsets.mapAttrsToList (user: config: "d /persist${config.home} 0700 ${user} 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); - }; + home-manager.users = lib.attrsets.mapAttrs (user: config: ({ + imports = [ inputs.impermanence.nixosModules.home-manager.impermanence ]; + + home.persistence."/persist${config.home}" = { + allowOther = true; + directories = [ + "Documents" + "Downloads" + "Music" + "Pictures" + "Videos" + "Templates" + "VMs" + "git" + ]; + }; + })) users; } diff --git a/users/common/configs/sops/default.nix b/users/common/configs/sops/default.nix index 12bc07f..ade20f5 100644 --- a/users/common/configs/sops/default.nix +++ b/users/common/configs/sops/default.nix @@ -1,17 +1,17 @@ { config, inputs, lib, ... }: let + users = lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users; sopsKeyPath = ".config/sops-nix/key.txt"; -in -{ - environment.sessionVariables.SOPS_AGE_KEY_FILE = "$HOME/${sopsKeyPath}"; +in { + home-manager.users = lib.attrsets.mapAttrs (user: config: ({ + imports = [ inputs.sops-nix.homeManagerModules.sops ]; - home-manager = { - sharedModules = [{ imports = [ inputs.sops-nix.homeManagerModules.sops ]; }]; + sops.age.keyFile = "/persist${config.home}/${sopsKeyPath}"; - 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); - }; + home = { + persistence."/persist${config.home}".files = [ sopsKeyPath ]; + sessionVariables.SOPS_AGE_KEY_FILE = "${config.home}/${sopsKeyPath}"; + }; + })) users; } diff --git a/users/common/configs/stylix/default.nix b/users/common/configs/stylix/default.nix deleted file mode 100644 index d47d730..0000000 --- a/users/common/configs/stylix/default.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ config, inputs, lib, ... }: - -{ - 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/vscode/default.nix b/users/common/configs/vscode/default.nix deleted file mode 100644 index 6114f72..0000000 --- a/users/common/configs/vscode/default.nix +++ /dev/null @@ -1,68 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - imports = [ - ./langs/nix.nix - ]; - - home-manager = { - sharedModules = [{ - programs.vscode = { - enable = true; - mutableExtensionsDir = false; - userSettings = { - "editor.accessibilitySupport" = "off"; - "editor.cursorBlinking" = "phase"; - "editor.cursorSmoothCaretAnimation" = "on"; - "editor.formatOnPaste" = true; - "editor.formatOnSave" = true; - "editor.formatOnType" = true; - "editor.indentSize" = "tabSize"; - "editor.inlineSuggest.enabled" = true; - "editor.largeFileOptimizations" = false; - "editor.linkedEditing" = true; - "editor.renderFinalNewline" = "on"; - "editor.smoothScrolling" = true; - "editor.stickyScroll.enabled" = true; - "editor.suggestSelection" = "first"; - "editor.unicodeHighlight.includeComments" = true; - "editor.unicodeHighlight.nonBasicASCII" = true; - "explorer.confirmDelete" = false; - "explorer.confirmDragAndDrop" = false; - "explorer.confirmPasteNative" = false; - "files.autoSave" = "afterDelay"; - "files.eol" = "\n"; - "files.insertFinalNewline" = true; - "files.trimFinalNewlines" = true; - "files.trimTrailingWhitespace" = true; - "git.allowForcePush" = true; - "git.alwaysSignOff" = true; - "git.autofetch" = "all"; - "git.closeDiffOnOperation" = true; - "git.confirmForcePush" = false; - "git.confirmSync" = false; - "git.enableCommitSigning" = true; - "git.enableSmartCommit" = true; - "git.ignoreRebaseWarning" = true; - "git.openRepositoryInParentFolders" = "always"; - "git.path" = "${pkgs.git}/bin/git"; - "mergeEditor.diffAlgorithm" = "advanced"; - "open-in-browser.default" = "firefox"; - "security.workspace.trust.enabled" = false; - "telemetry.telemetryLevel" = "off"; - "terminal.external.linuxExec" = "kitty"; - "terminal.integrated.confirmOnExit" = "hasChildProcesses"; - "terminal.integrated.copyOnSelection" = true; - "window.autoDetectHighContrast" = false; - "window.menuBarVisibility" = "toggle"; - "workbench.editor.historyBasedLanguageDetection" = true; - "workbench.list.smoothScrolling" = true; - }; - }; - }]; - - users = lib.attrsets.mapAttrs (user: config: ({ - home.persistence."/persist${config.home}".directories = [ ".config/Code" ]; - })) (lib.attrsets.filterAttrs (name: config: config.isNormalUser) config.users.users); - }; -} diff --git a/users/common/configs/vscode/langs/nix.nix b/users/common/configs/vscode/langs/nix.nix deleted file mode 100644 index 669c603..0000000 --- a/users/common/configs/vscode/langs/nix.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ pkgs, ... }: - -{ - home-manager = { - sharedModules = [{ - programs.vscode = { - userSettings = { - "nix.enableLanguageServer" = true; - "nix.formatterPath" = "nixpkgs-fmt"; - "nix.serverSettings" = {}; - }; - extensions = with pkgs; with vscode-extensions; [ - jnoortheen.nix-ide - ]; - }; - - home.packages = with pkgs; [ - nil - nixpkgs-fmt - ]; - }]; - }; -} diff --git a/users/common/configs/zsh/default.nix b/users/common/configs/zsh/default.nix deleted file mode 100644 index 35d084a..0000000 --- a/users/common/configs/zsh/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ config, lib, ... }: - -{ - 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 9355a8b..cff82d2 100644 --- a/users/common/default.nix +++ b/users/common/default.nix @@ -3,20 +3,9 @@ { imports = [ inputs.home-manager.nixosModules.default - ./extra.nix - + ./options.nix ./configs/persist ./configs/sops - - ./configs/firefox - ./configs/git - ./configs/gpg-agent - ./configs/hyprland - ./configs/kitty - ./configs/neovim - ./configs/stylix - ./configs/zsh - ./configs/vscode ]; home-manager = { diff --git a/users/common/extra.nix b/users/common/options.nix similarity index 99% rename from users/common/extra.nix rename to users/common/options.nix index 600cee7..ec86b38 100644 --- a/users/common/extra.nix +++ b/users/common/options.nix @@ -22,8 +22,7 @@ let description = "Base16 scheme to use for the user's color palette."; }; }; -in -{ +in { options = with lib; with types; { users.users = mkOption { type = attrsOf (submodule userOptions); diff --git a/users/configs/firefox/default.nix b/users/configs/firefox/default.nix new file mode 100644 index 0000000..7a4f449 --- /dev/null +++ b/users/configs/firefox/default.nix @@ -0,0 +1,93 @@ +{ user ? throw "user argument is required" }: { pkgs, ... }: + +{ + home-manager.users."${user.name}" = { + 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.default = { + 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"; + + "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" ]; + }; + + "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" ]; + }; + }; + }; + }; + }; + + home.persistence."/persist${user.home}".directories = [ ".mozilla" ]; + }; +} diff --git a/users/configs/git/default.nix b/users/configs/git/default.nix new file mode 100644 index 0000000..1054f83 --- /dev/null +++ b/users/configs/git/default.nix @@ -0,0 +1,26 @@ +{ user ? throw "user argument is required" }: { pkgs, ... }: + +{ + home-manager.users."${user.name}" = { + programs.git = { + enable = true; + lfs.enable = true; + userName = user.fullName; + userEmail = user.email; + 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"; + }; + }; + }; +} diff --git a/users/common/configs/gpg-agent/default.nix b/users/configs/gpg-agent/default.nix similarity index 55% rename from users/common/configs/gpg-agent/default.nix rename to users/configs/gpg-agent/default.nix index 9303ebc..0ea0a89 100644 --- a/users/common/configs/gpg-agent/default.nix +++ b/users/configs/gpg-agent/default.nix @@ -1,17 +1,17 @@ -{ config, lib, pkgs, ... }: +{ user ? throw "user argument is required" }: { pkgs, ... }: { - home-manager = { - sharedModules = [{ - services.gpg-agent = { - enable = true; - defaultCacheTtl = 31536000; - maxCacheTtl = 31536000; - }; + home-manager.users."${user.name}" = { + services.gpg-agent = { + enable = true; + defaultCacheTtl = 31536000; + maxCacheTtl = 31536000; + }; - systemd.user.services.gpg-agent-import = let + 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 + for keyfile in "${user.home}"/.config/sops-nix/secrets/gpg-agent/*.key; do passfile="''${keyfile%.key}.pass" if [ -f "$passfile" ]; then @@ -21,15 +21,14 @@ 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 + echo "$KEY_ID:6:" >> "${user.home}"/.gnupg/otrust.txt done done - gpg --import-ownertrust "$HOME"/.gnupg/otrust.txt - rm "$HOME"/.gnupg/otrust.txt + gpg --import-ownertrust "${user.home}"/.gnupg/otrust.txt + rm "${user.home}"/.gnupg/otrust.txt ''; - in - { + in { Unit = { Description = "Auto-import GPG keys"; Requires = [ "sops-nix.service" "gpg-agent.socket" ]; @@ -43,10 +42,8 @@ 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); + tmpfiles.rules = [ "d ${user.home}/.gnupg 0700 ${user.name} users -" ]; + }; }; } diff --git a/users/configs/hyprland/default.nix b/users/configs/hyprland/default.nix new file mode 100644 index 0000000..b30e957 --- /dev/null +++ b/users/configs/hyprland/default.nix @@ -0,0 +1,126 @@ +{ user ? throw "user argument is required" }: { lib, pkgs, ... }: + +{ + programs.hyprland.enable = true; + + home-manager.users."${user.name}" = { + wayland.windowManager.hyprland = { + enable = true; + settings = { + "$mod" = "SUPER"; + "$term" = "kitty"; + + bind = [ + "$mod, Return, exec, $term" + "$mod, r, exec, rofi -show drun" + "$mod, b, exec, firefox" + + "$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_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_CTRL, Space, workspaceopt, allfloat" + + "$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, 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, 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, Tab, cyclenext" + "$mod, Tab, bringactivetotop" + "$mod_SHIFT, Tab, cyclenext, prev" + "$mod_SHIFT, Tab, bringactivetotop" + + "$mod, f, fullscreen, 0" + "$mod, p, pin" + "$mod, Space, togglefloating" + "$mod, Space, centerwindow" + "$mod, q, killactive" + + "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; + }; + + exec-once = 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 ${user.wallpaper} + ''; + in "${init}/bin/hyprland-init"; + }; + }; + + programs.zsh.loginExtra = lib.mkAfter '' + if [ -z "''${WAYLAND_DISPLAY}" ] && [ ! -z "''${XDG_VTNR}" ] && [ "''${XDG_VTNR}" -eq 1 ]; then + ${pkgs.hyprland}/bin/hyprland &> /tmp/hyprland.log + fi + ''; + + home = { + sessionVariables.NIXOS_OZONE_WL = "1"; + packages = with pkgs; [ + swww + rofi-wayland + pavucontrol + ]; + }; + }; +} diff --git a/users/common/configs/kitty/default.nix b/users/configs/kitty/default.nix similarity index 54% rename from users/common/configs/kitty/default.nix rename to users/configs/kitty/default.nix index 3543875..c497f72 100644 --- a/users/common/configs/kitty/default.nix +++ b/users/configs/kitty/default.nix @@ -1,10 +1,12 @@ +{ user ? throw "user argument is required" }: { ... }: + { - home-manager.sharedModules = [{ + home-manager.users."${user.name}" = { programs.kitty = { enable = true; extraConfig = '' confirm_os_window_close 0 ''; }; - }]; + }; } diff --git a/users/common/configs/neovim/default.nix b/users/configs/neovim/default.nix similarity index 73% rename from users/common/configs/neovim/default.nix rename to users/configs/neovim/default.nix index c140164..250d349 100644 --- a/users/common/configs/neovim/default.nix +++ b/users/configs/neovim/default.nix @@ -1,5 +1,7 @@ +{ user ? throw "user argument is required" }: { ... }: + { - home-manager.sharedModules = [{ + home-manager.users."${user.name}" = { programs.neovim = { enable = true; defaultEditor = true; @@ -13,5 +15,5 @@ set smartindent ''; }; - }]; + }; } diff --git a/users/configs/stylix/default.nix b/users/configs/stylix/default.nix new file mode 100644 index 0000000..7aa35af --- /dev/null +++ b/users/configs/stylix/default.nix @@ -0,0 +1,13 @@ +{ user ? throw "user argument is required" }: { inputs, ... }: + +{ + home-manager.users."${user.name}" = { + imports = [ inputs.stylix.homeManagerModules.stylix ]; + + stylix = { + enable = true; + image = user.wallpaper; + base16Scheme = user.base16Scheme; + }; + }; +} diff --git a/users/configs/vscode/default.nix b/users/configs/vscode/default.nix new file mode 100644 index 0000000..2509cce --- /dev/null +++ b/users/configs/vscode/default.nix @@ -0,0 +1,64 @@ +{ user ? throw "user argument is required" }: { pkgs, ... }: + +{ + home-manager.users."${user.name}" = { + programs.vscode = { + enable = true; + mutableExtensionsDir = false; + userSettings = { + "editor.accessibilitySupport" = "off"; + "editor.cursorBlinking" = "phase"; + "editor.cursorSmoothCaretAnimation" = "on"; + "editor.formatOnPaste" = true; + "editor.formatOnSave" = true; + "editor.formatOnType" = true; + "editor.indentSize" = "tabSize"; + "editor.inlineSuggest.enabled" = true; + "editor.largeFileOptimizations" = false; + "editor.linkedEditing" = true; + "editor.renderFinalNewline" = "on"; + "editor.smoothScrolling" = true; + "editor.stickyScroll.enabled" = true; + "editor.suggestSelection" = "first"; + "editor.unicodeHighlight.includeComments" = true; + "editor.unicodeHighlight.nonBasicASCII" = true; + "explorer.confirmDelete" = false; + "explorer.confirmDragAndDrop" = false; + "explorer.confirmPasteNative" = false; + "files.autoSave" = "afterDelay"; + "files.eol" = "\n"; + "files.insertFinalNewline" = true; + "files.trimFinalNewlines" = true; + "files.trimTrailingWhitespace" = true; + "git.allowForcePush" = true; + "git.alwaysSignOff" = true; + "git.autofetch" = "all"; + "git.closeDiffOnOperation" = true; + "git.confirmForcePush" = false; + "git.confirmSync" = false; + "git.enableCommitSigning" = true; + "git.enableSmartCommit" = true; + "git.ignoreRebaseWarning" = true; + "git.openRepositoryInParentFolders" = "always"; + "git.path" = "${pkgs.git}/bin/git"; + "mergeEditor.diffAlgorithm" = "advanced"; + "open-in-browser.default" = "firefox"; + "security.workspace.trust.enabled" = false; + "telemetry.telemetryLevel" = "off"; + "terminal.external.linuxExec" = "kitty"; + "terminal.integrated.confirmOnExit" = "hasChildProcesses"; + "terminal.integrated.copyOnSelection" = true; + "window.autoDetectHighContrast" = false; + "window.menuBarVisibility" = "toggle"; + "workbench.editor.historyBasedLanguageDetection" = true; + "workbench.list.smoothScrolling" = true; + }; + }; + + imports = [ + ./langs/nix.nix + ]; + + home.persistence."/persist${user.home}".directories = [ ".config/Code" ]; + }; +} diff --git a/users/configs/vscode/langs/nix.nix b/users/configs/vscode/langs/nix.nix new file mode 100644 index 0000000..c4607b2 --- /dev/null +++ b/users/configs/vscode/langs/nix.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: + +{ + programs.vscode = { + userSettings = { + "nix.enableLanguageServer" = true; + "nix.formatterPath" = "nixpkgs-fmt"; + "nix.serverSettings" = {}; + }; + extensions = with pkgs; with vscode-extensions; [ + jnoortheen.nix-ide + ]; + }; + + home.packages = with pkgs; [ + nil + nixpkgs-fmt + ]; +} diff --git a/users/configs/zsh/default.nix b/users/configs/zsh/default.nix new file mode 100644 index 0000000..671bdee --- /dev/null +++ b/users/configs/zsh/default.nix @@ -0,0 +1,19 @@ +{ user ? throw "user argument is required" }: { ... }: + +{ + home-manager.users."${user.name}" = { + programs.zsh = { + enable = true; + autocd = true; + history = { + path = "${user.home}/.local/share/zsh/history"; + expireDuplicatesFirst = true; + }; + historySubstringSearch.enable = true; + autosuggestion.enable = true; + syntaxHighlighting.enable = true; + }; + + home.persistence."/persist${user.home}".directories = [ ".local/share/zsh" ]; + }; +} diff --git a/users/nick/default.nix b/users/nick/default.nix index 749b946..aa0d1ef 100644 --- a/users/nick/default.nix +++ b/users/nick/default.nix @@ -1,33 +1,19 @@ { config, pkgs, ... }: +let + user = config.users.users.nick; +in { - imports = [ ../common ]; - - sops.secrets.nick-password = { - sopsFile = ./secrets/secrets.yaml; - key = "password"; - neededForUsers = true; - }; - - home-manager.users.nick.sops = { - defaultSopsFile = ./secrets/secrets.yaml; - secrets = { - "git" = { path = "/home/nick/.git-credentials"; }; - "gpg-agent/pgp.key" = { }; - "gpg-agent/pgp.pass" = { }; - }; - }; + imports = [ + ./nogui.nix + (import ../configs/firefox { inherit user; }) + (import ../configs/hyprland { inherit user; }) + (import ../configs/kitty { inherit user; }) + (import ../configs/vscode { inherit user; }) + (import ../configs/stylix { inherit user; }) + ]; users.users.nick = { - isNormalUser = true; - home = "/home/nick"; - email = "nick@karaolidis.com"; - fullName = "Nikolaos Karaolidis"; - description = config.users.users.nick.fullName; - hashedPasswordFile = config.sops.secrets.nick-password.path; - extraGroups = [ "wheel" ]; - linger = true; - uid = 1000; wallpaper = ./wallpapers/clouds.png; base16Scheme = "${pkgs.base16-schemes}/share/themes/seti.yaml"; }; diff --git a/users/nick/nogui.nix b/users/nick/nogui.nix new file mode 100644 index 0000000..e57ec03 --- /dev/null +++ b/users/nick/nogui.nix @@ -0,0 +1,44 @@ +{ config, ... }: + +let + user = config.users.users.nick; +in +{ + imports = [ + ../common + (import ../configs/zsh { inherit user; }) + (import ../configs/git { inherit user; }) + (import ../configs/neovim { inherit user; }) + (import ../configs/gpg-agent { inherit user; }) + ]; + + sops.secrets.nick-password = { + sopsFile = ./secrets/secrets.yaml; + key = "password"; + neededForUsers = true; + }; + + users.users.nick = { + isNormalUser = true; + home = "/home/nick"; + email = "nick@karaolidis.com"; + fullName = "Nikolaos Karaolidis"; + description = config.users.users.nick.fullName; + hashedPasswordFile = config.sops.secrets.nick-password.path; + extraGroups = [ "wheel" ]; + linger = true; + uid = 1000; + }; + + home-manager.users.nick = { + home.homeDirectory = config.users.users.nick.home; + sops = { + defaultSopsFile = ./secrets/secrets.yaml; + secrets = { + "git" = { path = "/home/nick/.git-credentials"; }; + "gpg-agent/pgp.key" = { }; + "gpg-agent/pgp.pass" = { }; + }; + }; + }; +}