From 8c66b46a86afa21763766ef97d7c8be5f3954e2b Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 3 Jul 2023 11:00:10 -0400 Subject: [PATCH 01/21] home-manager: Use `path:` URI type for flake default (#3646) Nix interprets a path-like URI as a git repository if any of the path's parents is a git repository. Since home-manager uses a default flake URI of ~/.config/nixpkgs/flake.nix, if you have a git repository as your home directory and a '*' .gitignore it leads to the following problems: evaluating derivation 'git+file:///Users/dongcarl?dir=.config%2fnixpkgs#homeConfigurations."dongcarl".activationPackage' The following paths are ignored by one of your .gitignore files: .config This is solved by explicitly specifying the `path:` URI type prefix for the default flake URI argument. --- home-manager/home-manager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home-manager/home-manager b/home-manager/home-manager index 85c6da871..7b7b6fe26 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -156,7 +156,7 @@ function setFlakeAttribute() { fi if [[ -v configFlake ]]; then - FLAKE_ARG="$(dirname "$(readlink -f "$configFlake")")" + FLAKE_ARG="path:$(dirname "$(readlink -f "$configFlake")")" fi fi From c24deeca64538dcbc589ed8da9146e4ca9eb85b7 Mon Sep 17 00:00:00 2001 From: Paul Stadig Date: Mon, 3 Jul 2023 14:34:42 -0400 Subject: [PATCH 02/21] xfconf: remove properties with null values (#4192) Co-authored-by: Paul Stadig --- modules/misc/xfconf.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/misc/xfconf.nix b/modules/misc/xfconf.nix index ab21a66b3..f9858c5fa 100644 --- a/modules/misc/xfconf.nix +++ b/modules/misc/xfconf.nix @@ -76,7 +76,7 @@ in { settings = mkOption { type = with types; # xfIntVariant must come AFTER str; otherwise strings are treated as submodule imports... - let value = oneOf [ bool int float str xfIntVariant ]; + let value = nullOr (oneOf [ bool int float str xfIntVariant ]); in attrsOf (attrsOf (either value (listOf value))) // { description = "xfconf settings"; }; @@ -108,8 +108,11 @@ in { mkCommand = channel: property: value: '' $DRY_RUN_CMD ${pkgs.xfce.xfconf}/bin/xfconf-query \ ${ - escapeShellArgs - ([ "-n" "-c" channel "-p" "/${property}" ] ++ withType value) + escapeShellArgs ([ "-c" channel "-p" "/${property}" ] + ++ (if value == null then + [ "-r" ] + else + [ "-n" ] ++ withType value)) } ''; From 3be2abb2e6df41d9ddd5816032adf91691328225 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Tue, 4 Jul 2023 19:28:25 +1000 Subject: [PATCH 03/21] i18n: Use glibcLocales from NixOS if possible (#2333) (#4177) This will reduce the system closure size by about 200MB under NixOS by sharing the glibcLocales package. When home-manager is installed on Linux without the NixOS module, all glibc locales are installed, as before. Resolves: #2333 --- modules/config/i18n.nix | 32 +++++++++++++++++-- nixos/default.nix | 3 ++ tests/modules/config/i18n/default.nix | 22 +++++++++++++ .../home-environment/session-variables.nix | 2 +- tests/modules/misc/xdg/system-dirs.nix | 2 +- tests/modules/systemd/session-variables.nix | 4 +-- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/modules/config/i18n.nix b/modules/config/i18n.nix index e9b01b4ef..d5619afb7 100644 --- a/modules/config/i18n.nix +++ b/modules/config/i18n.nix @@ -15,15 +15,16 @@ # below for changes: # https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/development/libraries/glibc/nix-locale-archive.patch -{ lib, pkgs, ... }: +{ lib, pkgs, config, ... }: with lib; let + inherit (config.i18n) glibcLocales; - inherit (pkgs.glibcLocales) version; + inherit (glibcLocales) version; - archivePath = "${pkgs.glibcLocales}/lib/locale/locale-archive"; + archivePath = "${glibcLocales}/lib/locale/locale-archive"; # lookup the version of glibcLocales and set the appropriate environment vars localeVars = if versionAtLeast version "2.27" then { @@ -36,6 +37,31 @@ let in { meta.maintainers = with maintainers; [ midchildan ]; + options = { + i18n.glibcLocales = mkOption { + type = types.path; + description = '' + Customized glibcLocales package providing + the LOCALE_ARCHIVE_* environment variable. + + This option only applies to the Linux platform. + + When Home Manager is configured with NixOS, the default value + will be set to i18n.glibcLocales from the + system configuration. + ''; + example = literalExpression '' + pkgs.glibcLocales.override { + allLocales = false; + locales = [ "en_US.UTF-8/UTF-8" ]; + } + ''; + # NB. See nixos/default.nix for NixOS default. + default = pkgs.glibcLocales; + defaultText = literalExpression "pkgs.glibcLocales"; + }; + }; + config = mkIf pkgs.stdenv.hostPlatform.isLinux { # For shell sessions. home.sessionVariables = localeVars; diff --git a/nixos/default.nix b/nixos/default.nix index f8a5d6426..736a787df 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -23,6 +23,9 @@ in { # fontconfig by default. fonts.fontconfig.enable = lib.mkDefault (cfg.useUserPackages && config.fonts.fontconfig.enable); + + # Inherit glibcLocales setting from NixOS. + i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales; }]; }; } diff --git a/tests/modules/config/i18n/default.nix b/tests/modules/config/i18n/default.nix index 10b35b6f4..667b3b1d9 100644 --- a/tests/modules/config/i18n/default.nix +++ b/tests/modules/config/i18n/default.nix @@ -14,4 +14,26 @@ ''; }; }; + + i18n-custom-locales = { pkgs, ... }: { + config = let stub = pkgs.glibcLocalesCustom; + in { + test.stubs.glibcLocalesCustom = { + inherit (pkgs.glibcLocales) version; + outPath = null; # we need a real path for this stub + }; + + i18n.glibcLocales = stub; + + nmt.script = '' + hmEnvFile=home-path/etc/profile.d/hm-session-vars.sh + assertFileExists $hmEnvFile + assertFileRegex $hmEnvFile 'LOCALE_ARCHIVE_.*${stub}' + + envFile=home-files/.config/environment.d/10-home-manager.conf + assertFileExists $envFile + assertFileRegex $envFile 'LOCALE_ARCHIVE_.*${stub}' + ''; + }; + }; } diff --git a/tests/modules/home-environment/session-variables.nix b/tests/modules/home-environment/session-variables.nix index 08c988d2b..e1c8bedf8 100644 --- a/tests/modules/home-environment/session-variables.nix +++ b/tests/modules/home-environment/session-variables.nix @@ -9,7 +9,7 @@ let if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi export __HM_SESS_VARS_SOURCED=1 - export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive" + export LOCALE_ARCHIVE_2_27="${config.i18n.glibcLocales}/lib/locale/locale-archive" export V1="v1" export V2="v2-v1" export XDG_CACHE_HOME="/home/hm-user/.cache" diff --git a/tests/modules/misc/xdg/system-dirs.nix b/tests/modules/misc/xdg/system-dirs.nix index fa34ae0b5..432724bf8 100644 --- a/tests/modules/misc/xdg/system-dirs.nix +++ b/tests/modules/misc/xdg/system-dirs.nix @@ -10,7 +10,7 @@ assertFileExists $envFile assertFileContent $envFile ${ pkgs.writeText "expected" '' - LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive + LOCALE_ARCHIVE_2_27=${config.i18n.glibcLocales}/lib/locale/locale-archive XDG_CACHE_HOME=/home/hm-user/.cache XDG_CONFIG_DIRS=/etc/xdg:/foo/bar''${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS} XDG_CONFIG_HOME=/home/hm-user/.config diff --git a/tests/modules/systemd/session-variables.nix b/tests/modules/systemd/session-variables.nix index d234767f8..e427bbeea 100644 --- a/tests/modules/systemd/session-variables.nix +++ b/tests/modules/systemd/session-variables.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ config, pkgs, ... }: { systemd.user.sessionVariables = { @@ -11,7 +11,7 @@ assertFileExists $envFile assertFileContent $envFile ${ pkgs.writeText "expected" '' - LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive + LOCALE_ARCHIVE_2_27=${config.i18n.glibcLocales}/lib/locale/locale-archive V_int=1 V_str=2 XDG_CACHE_HOME=/home/hm-user/.cache From d895a774489cacd10c0140d54c4d158a53dcde90 Mon Sep 17 00:00:00 2001 From: Kylie McClain Date: Tue, 4 Jul 2023 06:11:28 -0400 Subject: [PATCH 04/21] vdirsyncer: synchronize metadata as well (#4167) --- modules/services/vdirsyncer.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/services/vdirsyncer.nix b/modules/services/vdirsyncer.nix index 75ad0bbae..ab9230d08 100644 --- a/modules/services/vdirsyncer.nix +++ b/modules/services/vdirsyncer.nix @@ -67,9 +67,11 @@ in { Service = { Type = "oneshot"; # TODO `vdirsyncer discover` - ExecStart = "${cfg.package}/bin/vdirsyncer ${ - concatStringsSep " " vdirsyncerOptions - } sync"; + ExecStart = let optStr = concatStringsSep " " vdirsyncerOptions; + in [ + "${cfg.package}/bin/vdirsyncer ${optStr} metasync" + "${cfg.package}/bin/vdirsyncer ${optStr} sync" + ]; }; }; From 4a26e21030a6ea9adbcc967812286bbe71fe45c5 Mon Sep 17 00:00:00 2001 From: Janik <80165193+Janik-Haag@users.noreply.github.com> Date: Tue, 4 Jul 2023 12:14:47 +0200 Subject: [PATCH 05/21] programs.khal moved highlight_event_days where appropriated and added tests --- modules/accounts/calendar.nix | 2 +- modules/programs/khal.nix | 2 +- tests/default.nix | 1 + tests/modules/programs/khal/config.nix | 32 +++++++++++++++++++++++++ tests/modules/programs/khal/default.nix | 1 + 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/modules/programs/khal/config.nix create mode 100644 tests/modules/programs/khal/default.nix diff --git a/modules/accounts/calendar.nix b/modules/accounts/calendar.nix index d53d3afa4..e96f2f2dd 100644 --- a/modules/accounts/calendar.nix +++ b/modules/accounts/calendar.nix @@ -12,7 +12,7 @@ let path = mkOption { type = types.str; default = "${cfg.basePath}/${name}"; - defaultText = "‹accounts.contact.basePath›/‹name›"; + defaultText = "‹accounts.calendar.basePath›/‹name›"; description = "The path of the storage."; }; diff --git a/modules/programs/khal.nix b/modules/programs/khal.nix index 555a3b805..209716a17 100644 --- a/modules/programs/khal.nix +++ b/modules/programs/khal.nix @@ -25,7 +25,6 @@ let genCalendarStr = name: value: concatStringsSep "\n" ([ "[[${name}]]" - "highlight_event_days = True" "path = ${ value.local.path + "/" + (optionalString (value.khal.type == "discover") value.khal.glob) @@ -158,6 +157,7 @@ in { # locale = definedAttrs (cfg.locale // { _module = null; }); default = optionalAttrs (!isNull primaryAccount) { + highlight_event_days = true; default_calendar = if isNull primaryAccount.primaryCollection then primaryAccount.name else diff --git a/tests/default.nix b/tests/default.nix index c04de3134..ae11853bd 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -88,6 +88,7 @@ import nmt { ./modules/programs/k9s ./modules/programs/kakoune ./modules/programs/kitty + ./modules/programs/khal ./modules/programs/ledger ./modules/programs/less ./modules/programs/lf diff --git a/tests/modules/programs/khal/config.nix b/tests/modules/programs/khal/config.nix new file mode 100644 index 000000000..1633d132b --- /dev/null +++ b/tests/modules/programs/khal/config.nix @@ -0,0 +1,32 @@ +{ ... }: + +{ + programs.khal.enable = true; + accounts.calendar = { + basePath = "$XDG_CONFIG_HOME/cal"; + accounts = { + test = { + primary = true; + primaryCollection = "test"; + khal = { + enable = true; + readOnly = true; + type = "calendar"; + }; + local.type = "filesystem"; + local.fileExt = ".ics"; + name = "test"; + remote = { + type = "http"; + url = "https://example.com/events.ical"; + }; + }; + }; + }; + + test.stubs = { khal = { }; }; + + nmt.script = '' + assertFileExists home-files/.config/khal/config + ''; +} diff --git a/tests/modules/programs/khal/default.nix b/tests/modules/programs/khal/default.nix new file mode 100644 index 000000000..999dc4c5a --- /dev/null +++ b/tests/modules/programs/khal/default.nix @@ -0,0 +1 @@ +{ khal-config = ./config.nix; } From b406b8d1bc90f6cd3e120d189b3e929f17ca4aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Tue, 4 Jul 2023 12:41:04 +0200 Subject: [PATCH 06/21] PULL_REQUEST_TEMPLATE.md: add maintainer cc section (#4193) --- .github/PULL_REQUEST_TEMPLATE.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e064d5aa1..af3efeaf7 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -40,3 +40,10 @@ Also make sure to read the guidelines found at - If this PR adds a new module - [ ] Added myself as module maintainer. See [example](https://github.com/nix-community/home-manager/blob/068ff76a10e95820f886ac46957edcff4e44621d/modules/programs/lesspipe.nix#L6). + +#### Maintainer CC + + From b66af0ac666d01f95c8f83e60b02a851700c048c Mon Sep 17 00:00:00 2001 From: Reza Almanda Date: Sat, 1 Jul 2023 15:50:12 +0200 Subject: [PATCH 07/21] Translate using Weblate (Indonesian) Currently translated at 27.7% (5 of 18 strings) Translate using Weblate (Indonesian) Currently translated at 33.3% (11 of 33 strings) Co-authored-by: Reza Almanda Translate-URL: https://hosted.weblate.org/projects/home-manager/cli/id/ Translate-URL: https://hosted.weblate.org/projects/home-manager/modules/id/ Translation: Home Manager/Home Manager CLI Translation: Home Manager/Home Manager Modules --- home-manager/po/id.po | 14 ++++++-------- modules/po/id.po | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/home-manager/po/id.po b/home-manager/po/id.po index 5a363753e..ef56f19a2 100644 --- a/home-manager/po/id.po +++ b/home-manager/po/id.po @@ -8,8 +8,8 @@ msgstr "" "Project-Id-Version: Home Manager\n" "Report-Msgid-Bugs-To: https://github.com/nix-community/home-manager/issues\n" "POT-Creation-Date: 2023-05-27 09:08+0200\n" -"PO-Revision-Date: 2023-06-22 09:51+0000\n" -"Last-Translator: Abdul V Vahry \n" +"PO-Revision-Date: 2023-07-01 13:50+0000\n" +"Last-Translator: Reza Almanda \n" "Language-Team: Indonesian \n" "Language: id\n" @@ -17,7 +17,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.18.1\n" +"X-Generator: Weblate 5.0-dev\n" #: home-manager/home-manager:71 msgid "No configuration file found at %s" @@ -27,12 +27,11 @@ msgstr "Tidak ada file konfigurasi yang ditemukan di %s" #. 'home.nix' or 'flake.nix'. #: home-manager/home-manager:88 home-manager/home-manager:92 #: home-manager/home-manager:154 -#, fuzzy msgid "" "Keeping your Home Manager %s in %s is deprecated,\n" "please move it to %s" msgstr "" -"Mempertahankan Pengelola Rumah Anda %s di %s tidak digunakan lagi,\n" +"Mempertahankan Pengelola Beranda Anda %s di %s tidak digunakan lagi,\n" "tolong pindahkan ke %s" #: home-manager/home-manager:99 @@ -45,9 +44,8 @@ msgstr "Tidak dapat menemukan direktori profil yang sesuai, mencoba %s dan %s" #. translators: Here "flake" is a noun that refers to the Nix Flakes feature. #: home-manager/home-manager:191 -#, fuzzy msgid "Can't inspect options of a flake configuration" -msgstr "Tidak dapat memeriksa opsi konfigurasi serpih" +msgstr "Tidak dapat memeriksa opsi konfigurasi flake" #: home-manager/home-manager:253 home-manager/home-manager:276 #: home-manager/home-manager:973 @@ -56,7 +54,7 @@ msgstr "%s: opsi tidak diketahui '%s'" #: home-manager/home-manager:258 home-manager/home-manager:974 msgid "Run '%s --help' for usage help" -msgstr "" +msgstr "Jalankan '%s --help' untuk bantuan penggunaan" #: home-manager/home-manager:284 home-manager/home-manager:383 msgid "The file %s already exists, leaving it unchanged..." diff --git a/modules/po/id.po b/modules/po/id.po index 6ebbcd0a4..37335ae2e 100644 --- a/modules/po/id.po +++ b/modules/po/id.po @@ -8,17 +8,20 @@ msgstr "" "Project-Id-Version: Home Manager Modules\n" "Report-Msgid-Bugs-To: https://github.com/nix-community/home-manager/issues\n" "POT-Creation-Date: 2023-05-27 09:08+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" +"PO-Revision-Date: 2023-07-01 13:50+0000\n" +"Last-Translator: Reza Almanda \n" +"Language-Team: Indonesian \n" "Language: id\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 5.0-dev\n" #: modules/files.nix:234 msgid "Creating home file links in %s" -msgstr "" +msgstr "Membuat tautan file beranda dalam %s" #: modules/files.nix:247 msgid "Cleaning up orphan links from %s" @@ -26,11 +29,11 @@ msgstr "" #: modules/files.nix:263 msgid "Creating profile generation %s" -msgstr "" +msgstr "Membuat profil %s" #: modules/files.nix:280 msgid "No change so reusing latest profile generation %s" -msgstr "" +msgstr "Tidak ada perubahan, jadi gunakan kembali pembuatan profil terbaru %s%s" #: modules/home-environment.nix:627 msgid "" @@ -50,11 +53,11 @@ msgstr "" #: modules/home-environment.nix:660 msgid "Activating %s" -msgstr "" +msgstr "Mengaktifkan %s" #: modules/lib-bash/activation-init.sh:22 msgid "Migrating profile from %s to %s" -msgstr "" +msgstr "Memigrasi profil dari %s ke %s" #: modules/lib-bash/activation-init.sh:53 msgid "Could not find suitable profile directory, tried %s and %s" From 2f78e6fcba61ce81536d19e6c662e55ab272d539 Mon Sep 17 00:00:00 2001 From: hitsmaxft Date: Tue, 27 Jun 2023 09:12:51 +0800 Subject: [PATCH 08/21] antidote: static file move to /tmp Make antidote create static file path with hm hash_id in /tmp. --- modules/programs/antidote.nix | 30 ++++++++++++-------- tests/modules/programs/antidote/antidote.nix | 2 -- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/programs/antidote.nix b/modules/programs/antidote.nix index 2c4a14d1f..f1fa044ce 100644 --- a/modules/programs/antidote.nix +++ b/modules/programs/antidote.nix @@ -8,11 +8,13 @@ let (optionalString (config.programs.zsh.dotDir != null) (config.programs.zsh.dotDir + "/")) + file; - zPluginStr = with lib; - (pluginNames: - optionalString (pluginNames != [ ]) "${concatStrings (map (name: '' - ${name} - '') pluginNames)}"); + zPluginStr = (pluginNames: + optionalString (pluginNames != [ ]) "${concatStrings (map (name: '' + ${name} + '') pluginNames)}"); + + parseHashId = path: + elemAt (builtins.match "/nix/store/([a-zA-Z0-9]+)-.*" path) 0; in { meta.maintainers = [ maintainers.hitsmaxft ]; @@ -33,20 +35,24 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - - home.file."${relToDotDir ".zsh_plugins.txt"}".text = zPluginStr cfg.plugins; - - ### move zsh_plugins.txt - programs.zsh.initExtraBeforeCompInit = '' + programs.zsh.initExtraBeforeCompInit = let + configFiles = pkgs.runCommand "hm_antidote-files" { } '' + echo "${zPluginStr cfg.plugins}" > $out + ''; + hashId = parseHashId "${configFiles}"; + in '' ## home-manager/antidote begin : source ${cfg.package}/share/antidote/antidote.zsh ${optionalString cfg.useFriendlyNames "zstyle ':antidote:bundle' use-friendly-names 'yes'"} - bundlefile=$HOME/${relToDotDir ".zsh_plugins.txt"} + + bundlefile=${configFiles} zstyle ':antidote:bundle' file $bundlefile - staticfile=$HOME/${relToDotDir ".zsh_plugins.zsh"} + staticfile=/tmp/tmp_hm_zsh_plugins.zsh-${hashId} zstyle ':antidote:static' file $staticfile + antidote load $bundlefile $staticfile + ## home-manager/antidote end ''; }; diff --git a/tests/modules/programs/antidote/antidote.nix b/tests/modules/programs/antidote/antidote.nix index 04ba6dd56..3d8fff6a9 100644 --- a/tests/modules/programs/antidote/antidote.nix +++ b/tests/modules/programs/antidote/antidote.nix @@ -24,7 +24,5 @@ in { 'antidote load' assertFileContains home-files/${relToDotDirCustom}/.zshrc \ "zstyle ':antidote:bundle' use-friendly-names 'yes'" - assertFileContains home-files/${relToDotDirCustom}/.zsh_plugins.txt \ - 'zsh-users/zsh-autosuggestions' ''; } From b23c7501f7e0a001486c9a5555a6c53ac7b08e85 Mon Sep 17 00:00:00 2001 From: Anton Mosich Date: Wed, 5 Jul 2023 12:23:31 +0200 Subject: [PATCH 09/21] i3: remove deprecated example in i3.config.startup (#4201) Deprecated in cacb8d4, see #265 --- modules/services/window-managers/i3-sway/lib/options.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/services/window-managers/i3-sway/lib/options.nix b/modules/services/window-managers/i3-sway/lib/options.nix index 0cbea6428..6c9f38da4 100644 --- a/modules/services/window-managers/i3-sway/lib/options.nix +++ b/modules/services/window-managers/i3-sway/lib/options.nix @@ -770,7 +770,7 @@ in { [ { command = "systemctl --user restart polybar"; always = true; notification = false; } { command = "dropbox start"; notification = false; } - { command = "firefox"; workspace = "1: web"; } + { command = "firefox"; } ]; '' else From 719de878f75b293eb3a8ab30943ae6ecf458c0a4 Mon Sep 17 00:00:00 2001 From: David Baynard Date: Fri, 7 Jul 2023 10:39:12 +0100 Subject: [PATCH 10/21] imapnotify: Add launchd agent (#3291) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * imapnotify: expose package (and exe) options There are multiple packages that provide an imapnotify interface. Those packages have differently named executables. This can now be customized. This change also means test configurations can use stub packages. * imapnotify: use/create config in configHome Exposing the configuration file makes testing imapnotify configurations much easier. It also allows for golden tests in home-manager. * imapnotify: extend with launchd agent Now that home-manager supports launchd agents, the imapnotify service can be configured (and enabled) for darwin. The configuration matches that of the linux/systemd version. In particular, by not setting a `UserName`, this runs as the user whose configuration includes the module. Due to the launchd `Program` implementation (it must take an absolute path) it is not possible to use that for the program and stub the path in tests. Instead, this uses `ProgramArguments` for the program name. The `ThrottleInterval` is equivalent to `RestartSec`. `KeepAlive` is equivalent to `Restart`. The `ExitTimeOut` default is 20 seconds, but goimapnotify should not time out — this is achieved by setting the `ExitTimeout` to 0. * imapnotify: add launchd plist test This only tests the generated plist (which is new), not the original systemd implementation, nor the json config file. (Note the lack of a newline at the end of the plist file.) --- modules/services/imapnotify.nix | 56 ++++++++++++++++--- tests/default.nix | 1 + .../modules/programs/goimapnotify/default.nix | 1 + .../modules/programs/goimapnotify/launchd.nix | 41 ++++++++++++++ .../programs/goimapnotify/launchd.plist | 29 ++++++++++ 5 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 tests/modules/programs/goimapnotify/default.nix create mode 100644 tests/modules/programs/goimapnotify/launchd.nix create mode 100644 tests/modules/programs/goimapnotify/launchd.plist diff --git a/modules/services/imapnotify.nix b/modules/services/imapnotify.nix index 0197ec54d..048e80974 100644 --- a/modules/services/imapnotify.nix +++ b/modules/services/imapnotify.nix @@ -8,6 +8,8 @@ let safeName = lib.replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ]; + configName = account: "imapnotify-${safeName account.name}-config.json"; + imapnotifyAccounts = filter (a: a.imapnotify.enable) (attrValues config.accounts.email.accounts); @@ -19,9 +21,10 @@ let Unit = { Description = "imapnotify for ${name}"; }; Service = { - ExecStart = "${pkgs.goimapnotify}/bin/goimapnotify -conf ${ - genAccountConfig account - }"; + ExecStart = + "${getExe cfg.package} -conf '${config.xdg.configHome}/imapnotify/${ + configName account + }'"; Restart = "always"; RestartSec = 30; Type = "simple"; @@ -34,8 +37,32 @@ let }; }; + genAccountAgent = account: + let name = safeName account.name; + in { + name = "imapnotify-${name}"; + value = { + enable = true; + config = { + ProgramArguments = [ + "${getExe cfg.package}" + "-conf" + "${config.xdg.configHome}/imapnotify/${configName account}" + ]; + KeepAlive = true; + ThrottleInterval = 30; + ExitTimeOut = 0; + ProcessType = "Background"; + RunAtLoad = true; + } // optionalAttrs account.notmuch.enable { + EnvironmentVariables.NOTMUCH_CONFIG = + "${config.xdg.configHome}/notmuch/default/config"; + }; + }; + }; + genAccountConfig = account: - pkgs.writeText "imapnotify-${safeName account.name}-config.json" (let + pkgs.writeText (configName account) (let port = if account.imap.port != null then account.imap.port else if account.imap.tls.enable then @@ -62,7 +89,17 @@ in { meta.maintainers = [ maintainers.nickhu ]; options = { - services.imapnotify = { enable = mkEnableOption "imapnotify"; }; + services.imapnotify = { + enable = mkEnableOption "imapnotify"; + + package = mkOption { + type = types.package; + default = pkgs.goimapnotify; + defaultText = literalExpression "pkgs.goimapnotify"; + example = literalExpression "pkgs.imapnotify"; + description = "The imapnotify package to use"; + }; + }; accounts.email.accounts = mkOption { type = with types; attrsOf (submodule (import ./imapnotify-accounts.nix)); @@ -79,8 +116,6 @@ in { + concatMapStringsSep ", " (a: a.name) badAccounts; }; in [ - (lib.hm.assertions.assertPlatform "services.imapnotify" pkgs - lib.platforms.linux) (checkAccounts (a: a.maildir == null) "maildir configuration") (checkAccounts (a: a.imap == null) "IMAP configuration") (checkAccounts (a: a.passwordCommand == null) "password command") @@ -88,5 +123,12 @@ in { ]; systemd.user.services = listToAttrs (map genAccountUnit imapnotifyAccounts); + + launchd.agents = listToAttrs (map genAccountAgent imapnotifyAccounts); + + xdg.configFile = listToAttrs (map (account: { + name = "imapnotify/${configName account}"; + value.source = genAccountConfig account; + }) imapnotifyAccounts); }; } diff --git a/tests/default.nix b/tests/default.nix index ae11853bd..fb5afbc9d 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -145,6 +145,7 @@ import nmt { ] ++ lib.optionals isDarwin [ ./modules/launchd ./modules/targets-darwin + ./modules/programs/goimapnotify ] ++ lib.optionals isLinux [ ./modules/config/i18n ./modules/i18n/input-method diff --git a/tests/modules/programs/goimapnotify/default.nix b/tests/modules/programs/goimapnotify/default.nix new file mode 100644 index 000000000..a2adc553d --- /dev/null +++ b/tests/modules/programs/goimapnotify/default.nix @@ -0,0 +1 @@ +{ goimapnotify-launchd = ./launchd.nix; } diff --git a/tests/modules/programs/goimapnotify/launchd.nix b/tests/modules/programs/goimapnotify/launchd.nix new file mode 100644 index 000000000..c7a81a3af --- /dev/null +++ b/tests/modules/programs/goimapnotify/launchd.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + imap.port = 993; + + imapnotify = { + enable = true; + boxes = [ "Inbox" ]; + onNotify = '' + ${pkgs.notmuch}/bin/notmuch new + ''; + }; + }; + }; + + services.imapnotify = { + enable = true; + package = (config.lib.test.mkStubPackage { + name = "goimapnotify"; + outPath = "@goimapnotify@"; + }); + }; + + nmt.script = let + serviceFileName = + "org.nix-community.home.imapnotify-hm-example.com.plist"; + in '' + serviceFile=LaunchAgents/${serviceFileName} + assertFileExists $serviceFile + assertFileContent $serviceFile ${./launchd.plist} + ''; + }; +} diff --git a/tests/modules/programs/goimapnotify/launchd.plist b/tests/modules/programs/goimapnotify/launchd.plist new file mode 100644 index 000000000..f8e45e8a3 --- /dev/null +++ b/tests/modules/programs/goimapnotify/launchd.plist @@ -0,0 +1,29 @@ + + + + + EnvironmentVariables + + NOTMUCH_CONFIG + /home/hm-user/.config/notmuch/default/config + + ExitTimeOut + 0 + KeepAlive + + Label + org.nix-community.home.imapnotify-hm-example.com + ProcessType + Background + ProgramArguments + + @goimapnotify@/bin/goimapnotify + -conf + /home/hm-user/.config/imapnotify/imapnotify-hm-example.com-config.json + + RunAtLoad + + ThrottleInterval + 30 + + \ No newline at end of file From 34db2f05219bcb0e41cc85490e4c338e2405546c Mon Sep 17 00:00:00 2001 From: simfu Date: Fri, 7 Jul 2023 13:57:22 +0200 Subject: [PATCH 11/21] unison: Allow using same option multiple times (#4208) Unison supports the same option to be given several times as a command line argument (e.g. unison -path xxx -path yyy). This commit adds Home Manager support for this by allowing a list of strings to be given to services.unison.pairs..commandOptions values. # Veuillez saisir le message de validation pour vos modifications. Les lignes --- modules/services/unison.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/services/unison.nix b/modules/services/unison.nix index d7f8a628a..e32f70522 100644 --- a/modules/services/unison.nix +++ b/modules/services/unison.nix @@ -22,7 +22,7 @@ let }; commandOptions = mkOption rec { - type = with types; attrsOf str; + type = with types; attrsOf (either str (listOf str)); apply = mergeAttrs default; default = { repeat = "watch"; @@ -36,6 +36,8 @@ let Additional command line options as a dictionary to pass to the unison program. + Use a list of strings to declare the same option multiple times. + See unison @@ -60,7 +62,9 @@ let }; }; - serialiseArg = key: val: escapeShellArg "-${key}=${escape [ "=" ] val}"; + serialiseArg = key: val: + concatStringsSep " " + (forEach (toList val) (x: escapeShellArg "-${key}=${escape [ "=" ] x}")); serialiseArgs = args: concatStringsSep " " (mapAttrsToList serialiseArg args); From f288310b7adf9775e405f251eb4920969fd8afa5 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sat, 8 Jul 2023 09:57:38 +0200 Subject: [PATCH 12/21] goimapnotify: remove test dependency on notmuch Also minor test cleanup. --- .../modules/programs/goimapnotify/launchd.nix | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/tests/modules/programs/goimapnotify/launchd.nix b/tests/modules/programs/goimapnotify/launchd.nix index c7a81a3af..3d4eca244 100644 --- a/tests/modules/programs/goimapnotify/launchd.nix +++ b/tests/modules/programs/goimapnotify/launchd.nix @@ -5,37 +5,36 @@ with lib; { imports = [ ../../accounts/email-test-accounts.nix ]; - config = { - accounts.email.accounts = { - "hm@example.com" = { - notmuch.enable = true; - imap.port = 993; + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + imap.port = 993; - imapnotify = { - enable = true; - boxes = [ "Inbox" ]; - onNotify = '' - ${pkgs.notmuch}/bin/notmuch new - ''; - }; + imapnotify = { + enable = true; + boxes = [ "Inbox" ]; + onNotify = '' + ${pkgs.notmuch}/bin/notmuch new + ''; }; }; - - services.imapnotify = { - enable = true; - package = (config.lib.test.mkStubPackage { - name = "goimapnotify"; - outPath = "@goimapnotify@"; - }); - }; - - nmt.script = let - serviceFileName = - "org.nix-community.home.imapnotify-hm-example.com.plist"; - in '' - serviceFile=LaunchAgents/${serviceFileName} - assertFileExists $serviceFile - assertFileContent $serviceFile ${./launchd.plist} - ''; }; + + services.imapnotify = { + enable = true; + package = (config.lib.test.mkStubPackage { + name = "goimapnotify"; + outPath = "@goimapnotify@"; + }); + }; + + test.stubs.notmuch = { }; + + nmt.script = let + serviceFileName = "org.nix-community.home.imapnotify-hm-example.com.plist"; + in '' + serviceFile=LaunchAgents/${serviceFileName} + assertFileExists $serviceFile + assertFileContent $serviceFile ${./launchd.plist} + ''; } From af715ed857f9d94086e4ef833949944bf0322521 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sat, 8 Jul 2023 10:12:35 +0200 Subject: [PATCH 13/21] tests: some minor cleanups --- .../programs/beets/mpdstats-external.nix | 44 ++++----- tests/modules/programs/beets/mpdstats.nix | 50 +++++----- tests/modules/programs/beets/mpdupdate.nix | 28 +++--- tests/modules/programs/nnn/nnn.nix | 96 +++++++++---------- .../programs/qutebrowser/keybindings.nix | 74 +++++++------- .../programs/qutebrowser/quickmarks.nix | 50 +++++----- .../modules/programs/qutebrowser/settings.nix | 76 +++++++-------- .../programs/terminator/config-file.nix | 42 ++++---- tests/modules/programs/topgrade/settings.nix | 50 +++++----- tests/modules/programs/vscode/keybindings.nix | 28 +++--- tests/modules/programs/vscode/tasks.nix | 2 +- tests/modules/programs/zplug/modules.nix | 88 ++++++++--------- 12 files changed, 298 insertions(+), 330 deletions(-) diff --git a/tests/modules/programs/beets/mpdstats-external.nix b/tests/modules/programs/beets/mpdstats-external.nix index f7e6d5b16..32a9c0736 100644 --- a/tests/modules/programs/beets/mpdstats-external.nix +++ b/tests/modules/programs/beets/mpdstats-external.nix @@ -1,29 +1,27 @@ -{ config, lib, pkgs, ... }: +{ config, ... }: { - config = { - home.stateVersion = "23.05"; + home.stateVersion = "23.05"; - programs.beets = { - enable = true; - package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; - mpdIntegration = { - enableStats = true; - host = "10.0.0.42"; - port = 6601; - }; + programs.beets = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; + mpdIntegration = { + enableStats = true; + host = "10.0.0.42"; + port = 6601; }; - - nmt.script = '' - assertFileExists home-files/.config/beets/config.yaml - assertFileContent \ - home-files/.config/beets/config.yaml \ - ${./mpdstats-external-expected.yaml} - - assertFileExists home-files/.config/systemd/user/beets-mpdstats.service - assertFileContent \ - home-files/.config/systemd/user/beets-mpdstats.service \ - ${./mpdstats-external-expected.service} - ''; }; + + nmt.script = '' + assertFileExists home-files/.config/beets/config.yaml + assertFileContent \ + home-files/.config/beets/config.yaml \ + ${./mpdstats-external-expected.yaml} + + assertFileExists home-files/.config/systemd/user/beets-mpdstats.service + assertFileContent \ + home-files/.config/systemd/user/beets-mpdstats.service \ + ${./mpdstats-external-expected.service} + ''; } diff --git a/tests/modules/programs/beets/mpdstats.nix b/tests/modules/programs/beets/mpdstats.nix index b4fba4a41..781eaa84a 100644 --- a/tests/modules/programs/beets/mpdstats.nix +++ b/tests/modules/programs/beets/mpdstats.nix @@ -1,31 +1,29 @@ -{ config, lib, pkgs, ... }: +{ config, ... }: { - config = { - home.stateVersion = "23.05"; + home.stateVersion = "23.05"; - services.mpd = { - enable = true; - musicDirectory = "/my/music/dir"; - network.port = 4242; - }; - - programs.beets = { - enable = true; - package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; - mpdIntegration.enableStats = true; - }; - - nmt.script = '' - assertFileExists home-files/.config/beets/config.yaml - assertFileContent \ - home-files/.config/beets/config.yaml \ - ${./mpdstats-expected.yaml} - - assertFileExists home-files/.config/systemd/user/beets-mpdstats.service - assertFileContent \ - home-files/.config/systemd/user/beets-mpdstats.service \ - ${./mpdstats-expected.service} - ''; + services.mpd = { + enable = true; + musicDirectory = "/my/music/dir"; + network.port = 4242; }; + + programs.beets = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; + mpdIntegration.enableStats = true; + }; + + nmt.script = '' + assertFileExists home-files/.config/beets/config.yaml + assertFileContent \ + home-files/.config/beets/config.yaml \ + ${./mpdstats-expected.yaml} + + assertFileExists home-files/.config/systemd/user/beets-mpdstats.service + assertFileContent \ + home-files/.config/systemd/user/beets-mpdstats.service \ + ${./mpdstats-expected.service} + ''; } diff --git a/tests/modules/programs/beets/mpdupdate.nix b/tests/modules/programs/beets/mpdupdate.nix index 3516ae205..b73da81e8 100644 --- a/tests/modules/programs/beets/mpdupdate.nix +++ b/tests/modules/programs/beets/mpdupdate.nix @@ -1,20 +1,18 @@ -{ config, lib, pkgs, ... }: +{ config, ... }: { - config = { - home.stateVersion = "23.05"; + home.stateVersion = "23.05"; - programs.beets = { - enable = true; - package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; - mpdIntegration.enableUpdate = true; - }; - - nmt.script = '' - assertFileExists home-files/.config/beets/config.yaml - assertFileContent \ - home-files/.config/beets/config.yaml \ - ${./mpdupdate-expected.yaml} - ''; + programs.beets = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; + mpdIntegration.enableUpdate = true; }; + + nmt.script = '' + assertFileExists home-files/.config/beets/config.yaml + assertFileContent \ + home-files/.config/beets/config.yaml \ + ${./mpdupdate-expected.yaml} + ''; } diff --git a/tests/modules/programs/nnn/nnn.nix b/tests/modules/programs/nnn/nnn.nix index 7a01fd854..948317ae7 100644 --- a/tests/modules/programs/nnn/nnn.nix +++ b/tests/modules/programs/nnn/nnn.nix @@ -1,55 +1,53 @@ -{ config, lib, pkgs, ... }: +{ pkgs, ... }: { - config = { - programs.nnn = { - enable = true; - bookmarks = { - d = "~/Documents"; - D = "~/Downloads"; - p = "~/Pictures"; - v = "~/Videos"; - }; - package = pkgs.nnnDummy; - extraPackages = with pkgs; [ foo bar ]; - plugins = { - src = ./plugins; - mappings = { - c = "fzcd"; - f = "finder"; - v = "imgview"; - }; - }; + programs.nnn = { + enable = true; + bookmarks = { + d = "~/Documents"; + D = "~/Downloads"; + p = "~/Pictures"; + v = "~/Videos"; }; - - test.stubs = { - nnnDummy.buildScript = '' - runHook preInstall - - mkdir -p "$out/bin" - touch "$out/bin/nnn" - chmod +x "$out/bin/nnn" - - runHook postInstall - ''; - foo = { name = "foo"; }; - bar = { name = "bar"; }; - }; - - nmt = { - description = - "Check if the binary is correctly wrapped and if the symlinks are made"; - script = '' - assertDirectoryExists home-files/.config/nnn/plugins - - for bookmark in 'export NNN_BMS' '~/Downloads' '~/Documents' '~/Pictures' '~/Videos'; do - assertFileRegex home-path/bin/nnn "$bookmark" - done - - for plugin in 'export NNN_PLUG' 'fzcd' 'finder' 'imgview'; do - assertFileRegex home-path/bin/nnn "$plugin" - done - ''; + package = pkgs.nnnDummy; + extraPackages = with pkgs; [ foo bar ]; + plugins = { + src = ./plugins; + mappings = { + c = "fzcd"; + f = "finder"; + v = "imgview"; + }; }; }; + + test.stubs = { + nnnDummy.buildScript = '' + runHook preInstall + + mkdir -p "$out/bin" + touch "$out/bin/nnn" + chmod +x "$out/bin/nnn" + + runHook postInstall + ''; + foo = { name = "foo"; }; + bar = { name = "bar"; }; + }; + + nmt = { + description = + "Check if the binary is correctly wrapped and if the symlinks are made"; + script = '' + assertDirectoryExists home-files/.config/nnn/plugins + + for bookmark in 'export NNN_BMS' '~/Downloads' '~/Documents' '~/Pictures' '~/Videos'; do + assertFileRegex home-path/bin/nnn "$bookmark" + done + + for plugin in 'export NNN_PLUG' 'fzcd' 'finder' 'imgview'; do + assertFileRegex home-path/bin/nnn "$plugin" + done + ''; + }; } diff --git a/tests/modules/programs/qutebrowser/keybindings.nix b/tests/modules/programs/qutebrowser/keybindings.nix index 258c57ad3..00e730efa 100644 --- a/tests/modules/programs/qutebrowser/keybindings.nix +++ b/tests/modules/programs/qutebrowser/keybindings.nix @@ -1,47 +1,43 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ lib, pkgs, ... }: { - config = { - programs.qutebrowser = { - enable = true; + programs.qutebrowser = { + enable = true; - enableDefaultBindings = false; + enableDefaultBindings = false; - keyBindings = { - normal = { - "" = "spawn mpv {url}"; - ",l" = ''config-cycle spellcheck.languages ["en-GB"] ["en-US"]''; - "" = mkMerge [ - "config-cycle tabs.show never always" - "config-cycle statusbar.show in-mode always" - "config-cycle scrolling.bar never always" - ]; - }; - prompt = { "" = "prompt-yes"; }; + keyBindings = { + normal = { + "" = "spawn mpv {url}"; + ",l" = ''config-cycle spellcheck.languages ["en-GB"] ["en-US"]''; + "" = lib.mkMerge [ + "config-cycle tabs.show never always" + "config-cycle statusbar.show in-mode always" + "config-cycle scrolling.bar never always" + ]; }; + prompt = { "" = "prompt-yes"; }; }; - - test.stubs.qutebrowser = { }; - - nmt.script = let - qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then - ".qutebrowser/config.py" - else - ".config/qutebrowser/config.py"; - in '' - assertFileContent \ - home-files/${qutebrowserConfig} \ - ${ - pkgs.writeText "qutebrowser-expected-config.py" '' - config.load_autoconfig(False) - c.bindings.default = {} - config.bind(",l", "config-cycle spellcheck.languages [\"en-GB\"] [\"en-US\"]", mode="normal") - config.bind("", "spawn mpv {url}", mode="normal") - config.bind("", "config-cycle tabs.show never always ;; config-cycle statusbar.show in-mode always ;; config-cycle scrolling.bar never always", mode="normal") - config.bind("", "prompt-yes", mode="prompt")'' - } - ''; }; + + test.stubs.qutebrowser = { }; + + nmt.script = let + qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then + ".qutebrowser/config.py" + else + ".config/qutebrowser/config.py"; + in '' + assertFileContent \ + home-files/${qutebrowserConfig} \ + ${ + pkgs.writeText "qutebrowser-expected-config.py" '' + config.load_autoconfig(False) + c.bindings.default = {} + config.bind(",l", "config-cycle spellcheck.languages [\"en-GB\"] [\"en-US\"]", mode="normal") + config.bind("", "spawn mpv {url}", mode="normal") + config.bind("", "config-cycle tabs.show never always ;; config-cycle statusbar.show in-mode always ;; config-cycle scrolling.bar never always", mode="normal") + config.bind("", "prompt-yes", mode="prompt")'' + } + ''; } diff --git a/tests/modules/programs/qutebrowser/quickmarks.nix b/tests/modules/programs/qutebrowser/quickmarks.nix index 1491a1e67..9437fc614 100644 --- a/tests/modules/programs/qutebrowser/quickmarks.nix +++ b/tests/modules/programs/qutebrowser/quickmarks.nix @@ -1,33 +1,29 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ pkgs, ... }: { - config = { - programs.qutebrowser = { - enable = true; + programs.qutebrowser = { + enable = true; - quickmarks = { - nixpkgs = "https://github.com/NixOS/nixpkgs"; - home-manager = "https://github.com/nix-community/home-manager"; - }; + quickmarks = { + nixpkgs = "https://github.com/NixOS/nixpkgs"; + home-manager = "https://github.com/nix-community/home-manager"; }; - - test.stubs.qutebrowser = { }; - - nmt.script = let - quickmarksFile = if pkgs.stdenv.hostPlatform.isDarwin then - ".qutebrowser/quickmarks" - else - ".config/qutebrowser/quickmarks"; - in '' - assertFileContent \ - home-files/${quickmarksFile} \ - ${ - pkgs.writeText "qutebrowser-expected-quickmarks" '' - home-manager https://github.com/nix-community/home-manager - nixpkgs https://github.com/NixOS/nixpkgs'' - } - ''; }; + + test.stubs.qutebrowser = { }; + + nmt.script = let + quickmarksFile = if pkgs.stdenv.hostPlatform.isDarwin then + ".qutebrowser/quickmarks" + else + ".config/qutebrowser/quickmarks"; + in '' + assertFileContent \ + home-files/${quickmarksFile} \ + ${ + pkgs.writeText "qutebrowser-expected-quickmarks" '' + home-manager https://github.com/nix-community/home-manager + nixpkgs https://github.com/NixOS/nixpkgs'' + } + ''; } diff --git a/tests/modules/programs/qutebrowser/settings.nix b/tests/modules/programs/qutebrowser/settings.nix index dca6ae6f5..e2cf3915f 100644 --- a/tests/modules/programs/qutebrowser/settings.nix +++ b/tests/modules/programs/qutebrowser/settings.nix @@ -1,50 +1,46 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ pkgs, ... }: { - config = { - programs.qutebrowser = { - enable = true; + programs.qutebrowser = { + enable = true; - settings = { - colors = { - hints = { - bg = "#000000"; - fg = "#ffffff"; - }; - tabs.bar.bg = "#000000"; + settings = { + colors = { + hints = { + bg = "#000000"; + fg = "#ffffff"; }; - spellcheck.languages = [ "en-US" "sv-SE" ]; - tabs.tabs_are_windows = true; + tabs.bar.bg = "#000000"; }; - - extraConfig = '' - # Extra qutebrowser configuration. - ''; + spellcheck.languages = [ "en-US" "sv-SE" ]; + tabs.tabs_are_windows = true; }; - test.stubs.qutebrowser = { }; - - nmt.script = let - qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then - ".qutebrowser/config.py" - else - ".config/qutebrowser/config.py"; - in '' - assertFileContent \ - home-files/${qutebrowserConfig} \ - ${ - pkgs.writeText "qutebrowser-expected-config.py" '' - config.load_autoconfig(False) - c.colors.hints.bg = "#000000" - c.colors.hints.fg = "#ffffff" - c.colors.tabs.bar.bg = "#000000" - c.spellcheck.languages = ["en-US", "sv-SE"] - c.tabs.tabs_are_windows = True - # Extra qutebrowser configuration. - '' - } + extraConfig = '' + # Extra qutebrowser configuration. ''; }; + + test.stubs.qutebrowser = { }; + + nmt.script = let + qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then + ".qutebrowser/config.py" + else + ".config/qutebrowser/config.py"; + in '' + assertFileContent \ + home-files/${qutebrowserConfig} \ + ${ + pkgs.writeText "qutebrowser-expected-config.py" '' + config.load_autoconfig(False) + c.colors.hints.bg = "#000000" + c.colors.hints.fg = "#ffffff" + c.colors.tabs.bar.bg = "#000000" + c.spellcheck.languages = ["en-US", "sv-SE"] + c.tabs.tabs_are_windows = True + # Extra qutebrowser configuration. + '' + } + ''; } diff --git a/tests/modules/programs/terminator/config-file.nix b/tests/modules/programs/terminator/config-file.nix index 50b9c42e7..9e4e5d6e6 100644 --- a/tests/modules/programs/terminator/config-file.nix +++ b/tests/modules/programs/terminator/config-file.nix @@ -1,24 +1,24 @@ -{ config, lib, pkgs, ... }: { - config = { - programs.terminator = { - enable = true; - config = { - global_config.borderless = true; - profiles.default.background_color = "#002b36"; - }; +{ pkgs, ... }: + +{ + programs.terminator = { + enable = true; + config = { + global_config.borderless = true; + profiles.default.background_color = "#002b36"; }; - - test.stubs.terminator = { }; - - nmt.script = '' - assertFileContent home-files/.config/terminator/config ${ - pkgs.writeText "expected" '' - [global_config] - borderless = True - [profiles] - [[default]] - background_color = "#002b36"'' - } - ''; }; + + test.stubs.terminator = { }; + + nmt.script = '' + assertFileContent home-files/.config/terminator/config ${ + pkgs.writeText "expected" '' + [global_config] + borderless = True + [profiles] + [[default]] + background_color = "#002b36"'' + } + ''; } diff --git a/tests/modules/programs/topgrade/settings.nix b/tests/modules/programs/topgrade/settings.nix index a8f5c6d10..e80e98b86 100644 --- a/tests/modules/programs/topgrade/settings.nix +++ b/tests/modules/programs/topgrade/settings.nix @@ -1,36 +1,32 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ lib, ... }: { - config = { - programs.topgrade = { - enable = true; + programs.topgrade = { + enable = true; - settings = mkMerge [ - { - disable = [ "sdkman" "flutter" "node" "nix" "home_manager" ]; + settings = lib.mkMerge [ + { + disable = [ "sdkman" "flutter" "node" "nix" "home_manager" ]; - remote_topgrades = [ "backup" "ci" ]; + remote_topgrades = [ "backup" "ci" ]; - remote_topgrade_path = "bin/topgrade"; - } + remote_topgrade_path = "bin/topgrade"; + } - { - set_title = false; - cleanup = true; + { + set_title = false; + cleanup = true; - commands = { "Purge unused APT packages" = "sudo apt autoremove"; }; - } - ]; - }; - - test.stubs.topgrade = { }; - - nmt.script = '' - assertFileContent \ - home-files/.config/topgrade.toml \ - ${./settings-expected.toml} - ''; + commands = { "Purge unused APT packages" = "sudo apt autoremove"; }; + } + ]; }; + + test.stubs.topgrade = { }; + + nmt.script = '' + assertFileContent \ + home-files/.config/topgrade.toml \ + ${./settings-expected.toml} + ''; } diff --git a/tests/modules/programs/vscode/keybindings.nix b/tests/modules/programs/vscode/keybindings.nix index ed457a9ba..64212e29a 100644 --- a/tests/modules/programs/vscode/keybindings.nix +++ b/tests/modules/programs/vscode/keybindings.nix @@ -1,7 +1,5 @@ # Test that keybindings.json is created correctly. -{ config, lib, pkgs, ... }: - -with lib; +{ pkgs, ... }: let bindings = [ @@ -65,18 +63,16 @@ let ''; in { - config = { - programs.vscode = { - enable = true; - keybindings = bindings; - package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; - }; - - nmt.script = '' - assertFileExists "home-files/${keybindingsPath}" - assertFileContent "home-files/${keybindingsPath}" "${expectedKeybindings}" - - assertPathNotExists "home-files/${settingsPath}" - ''; + programs.vscode = { + enable = true; + keybindings = bindings; + package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; }; + + nmt.script = '' + assertFileExists "home-files/${keybindingsPath}" + assertFileContent "home-files/${keybindingsPath}" "${expectedKeybindings}" + + assertPathNotExists "home-files/${settingsPath}" + ''; } diff --git a/tests/modules/programs/vscode/tasks.nix b/tests/modules/programs/vscode/tasks.nix index f0d283805..ea85b3d6c 100644 --- a/tests/modules/programs/vscode/tasks.nix +++ b/tests/modules/programs/vscode/tasks.nix @@ -1,4 +1,4 @@ -{ pkgs, config, ... }: +{ pkgs, ... }: let diff --git a/tests/modules/programs/zplug/modules.nix b/tests/modules/programs/zplug/modules.nix index 90b70f0ba..1256e33c2 100644 --- a/tests/modules/programs/zplug/modules.nix +++ b/tests/modules/programs/zplug/modules.nix @@ -1,52 +1,48 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ config, pkgs, ... }: { - config = { - programs.zsh = { + programs.zsh = { + enable = true; + zplug = { enable = true; - zplug = { - enable = true; - zplugHome = pkgs.emptyDirectory; - plugins = [ - { - name = "plugins/git"; - tags = [ "from:oh-my-zsh" ]; - } - { - name = "lib/clipboard"; - tags = [ "from:oh-my-zsh" ''if:"[[ $OSTYPE == *darwin* ]]"'' ]; - } - ]; - }; + zplugHome = pkgs.emptyDirectory; + plugins = [ + { + name = "plugins/git"; + tags = [ "from:oh-my-zsh" ]; + } + { + name = "lib/clipboard"; + tags = [ "from:oh-my-zsh" ''if:"[[ $OSTYPE == *darwin* ]]"'' ]; + } + ]; }; - - test.stubs = { - zplug = { }; - zsh = { }; - }; - - nmt.script = '' - assertFileContains home-files/.zshrc \ - 'source @zplug@/share/zplug/init.zsh' - - assertFileContains home-files/.zshrc \ - 'zplug "plugins/git", from:oh-my-zsh' - - assertFileContains home-files/.zshrc \ - 'zplug "lib/clipboard", from:oh-my-zsh, if:"[[ $OSTYPE == *darwin* ]]"' - - assertFileContains home-files/.zshrc \ - 'if ! zplug check; then - zplug install - fi' - - assertFileRegex home-files/.zshrc \ - '^zplug load$' - - assertFileContains home-files/.zshrc \ - 'export ZPLUG_HOME=${config.programs.zsh.zplug.zplugHome}' - ''; }; + + test.stubs = { + zplug = { }; + zsh = { }; + }; + + nmt.script = '' + assertFileContains home-files/.zshrc \ + 'source @zplug@/share/zplug/init.zsh' + + assertFileContains home-files/.zshrc \ + 'zplug "plugins/git", from:oh-my-zsh' + + assertFileContains home-files/.zshrc \ + 'zplug "lib/clipboard", from:oh-my-zsh, if:"[[ $OSTYPE == *darwin* ]]"' + + assertFileContains home-files/.zshrc \ + 'if ! zplug check; then + zplug install + fi' + + assertFileRegex home-files/.zshrc \ + '^zplug load$' + + assertFileContains home-files/.zshrc \ + 'export ZPLUG_HOME=${config.programs.zsh.zplug.zplugHome}' + ''; } From 050d01a62cfe19642fb193084acf34a428a67223 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Mon, 27 Mar 2023 12:25:17 -0600 Subject: [PATCH 14/21] darcs: add module --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/darcs.nix | 52 +++++++++++++++++++ tests/default.nix | 1 + .../programs/darcs/author-expected.txt | 2 + tests/modules/programs/darcs/author.nix | 17 ++++++ .../programs/darcs/boring-expected.txt | 3 ++ tests/modules/programs/darcs/boring.nix | 14 +++++ tests/modules/programs/darcs/default.nix | 4 ++ 9 files changed, 101 insertions(+) create mode 100644 modules/programs/darcs.nix create mode 100644 tests/modules/programs/darcs/author-expected.txt create mode 100644 tests/modules/programs/darcs/author.nix create mode 100644 tests/modules/programs/darcs/boring-expected.txt create mode 100644 tests/modules/programs/darcs/boring.nix create mode 100644 tests/modules/programs/darcs/default.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f6584383a..39527efea 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1143,6 +1143,13 @@ in A new module is available: 'services.ssh-agent' ''; } + + { + time = "2023-07-08T08:27:41+00:00"; + message = '' + A new modules is available: 'programs.darcs' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index f6a15c020..6db9c29f3 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -70,6 +70,7 @@ let ./programs/chromium.nix ./programs/command-not-found/command-not-found.nix ./programs/comodoro.nix + ./programs/darcs.nix ./programs/dircolors.nix ./programs/direnv.nix ./programs/discocss.nix diff --git a/modules/programs/darcs.nix b/modules/programs/darcs.nix new file mode 100644 index 000000000..a2a45cba4 --- /dev/null +++ b/modules/programs/darcs.nix @@ -0,0 +1,52 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.darcs; + +in { + meta.maintainers = with maintainers; [ chris-martin ]; + + options = { + programs.darcs = { + enable = mkEnableOption "darcs"; + + package = mkPackageOption pkgs "darcs" { }; + + author = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "Fred Bloggs " ]; + description = '' + If this list has a single entry, it will be used as the author + when you record a patch. If there are multiple entries, Darcs + will prompt you to choose one of them. + ''; + }; + + boring = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "^.idea$" ".iml$" "^.stack-work$" ]; + description = "File patterns to ignore"; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + { home.packages = [ cfg.package ]; } + + (mkIf (cfg.author != [ ]) { + home.file.".darcs/author".text = + concatMapStrings (x: x + "\n") cfg.author; + }) + + (mkIf (cfg.boring != [ ]) { + home.file.".darcs/boring".text = + concatMapStrings (x: x + "\n") cfg.boring; + }) + + ]); +} diff --git a/tests/default.nix b/tests/default.nix index fb5afbc9d..738b158b2 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -68,6 +68,7 @@ import nmt { ./modules/programs/browserpass ./modules/programs/btop ./modules/programs/comodoro + ./modules/programs/darcs ./modules/programs/dircolors ./modules/programs/direnv ./modules/programs/emacs diff --git a/tests/modules/programs/darcs/author-expected.txt b/tests/modules/programs/darcs/author-expected.txt new file mode 100644 index 000000000..94be11277 --- /dev/null +++ b/tests/modules/programs/darcs/author-expected.txt @@ -0,0 +1,2 @@ +Real Person +Real Person diff --git a/tests/modules/programs/darcs/author.nix b/tests/modules/programs/darcs/author.nix new file mode 100644 index 000000000..26cfb469e --- /dev/null +++ b/tests/modules/programs/darcs/author.nix @@ -0,0 +1,17 @@ +{ pkgs, ... }: + +{ + config = { + programs.darcs = { + enable = true; + author = [ + "Real Person " + "Real Person " + ]; + }; + + nmt.script = '' + assertFileContent home-files/.darcs/author ${./author-expected.txt} + ''; + }; +} diff --git a/tests/modules/programs/darcs/boring-expected.txt b/tests/modules/programs/darcs/boring-expected.txt new file mode 100644 index 000000000..4a41138cd --- /dev/null +++ b/tests/modules/programs/darcs/boring-expected.txt @@ -0,0 +1,3 @@ +^.idea$ +.iml$ +^.stack-work$ diff --git a/tests/modules/programs/darcs/boring.nix b/tests/modules/programs/darcs/boring.nix new file mode 100644 index 000000000..ae02f18cf --- /dev/null +++ b/tests/modules/programs/darcs/boring.nix @@ -0,0 +1,14 @@ +{ pkgs, ... }: + +{ + config = { + programs.darcs = { + enable = true; + boring = [ "^.idea$" ".iml$" "^.stack-work$" ]; + }; + + nmt.script = '' + assertFileContent home-files/.darcs/boring ${./boring-expected.txt} + ''; + }; +} diff --git a/tests/modules/programs/darcs/default.nix b/tests/modules/programs/darcs/default.nix new file mode 100644 index 000000000..789841239 --- /dev/null +++ b/tests/modules/programs/darcs/default.nix @@ -0,0 +1,4 @@ +{ + darcs-author = ./author.nix; + darcs-boring = ./boring.nix; +} From 069d450b6d2da9369ee5a8ddb2dbf909d3535471 Mon Sep 17 00:00:00 2001 From: Tobias Markus Date: Fri, 7 Jul 2023 14:40:34 +0200 Subject: [PATCH 15/21] pyenv: add module Adds a module for pyenv (https://github.com/pyenv/pyenv). --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/pyenv.nix | 79 ++++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/pyenv/bash.nix | 17 +++++ tests/modules/programs/pyenv/default.nix | 5 ++ tests/modules/programs/pyenv/fish.nix | 17 +++++ tests/modules/programs/pyenv/zsh.nix | 17 +++++ 8 files changed, 144 insertions(+) create mode 100644 modules/programs/pyenv.nix create mode 100644 tests/modules/programs/pyenv/bash.nix create mode 100644 tests/modules/programs/pyenv/default.nix create mode 100644 tests/modules/programs/pyenv/fish.nix create mode 100644 tests/modules/programs/pyenv/zsh.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 39527efea..4b432dfaf 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1150,6 +1150,13 @@ in A new modules is available: 'programs.darcs' ''; } + + { + time = "2023-07-08T09:21:06+00:00"; + message = '' + A new module is available: 'programs.pyenv'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 6db9c29f3..8822eeed8 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -169,6 +169,7 @@ let ./programs/pls.nix ./programs/powerline-go.nix ./programs/pubs.nix + ./programs/pyenv.nix ./programs/pylint.nix ./programs/qutebrowser.nix ./programs/rbw.nix diff --git a/modules/programs/pyenv.nix b/modules/programs/pyenv.nix new file mode 100644 index 000000000..a83713bbf --- /dev/null +++ b/modules/programs/pyenv.nix @@ -0,0 +1,79 @@ +{ config, pkgs, lib, ... }: + +let + + cfg = config.programs.pyenv; + + tomlFormat = pkgs.formats.toml { }; + +in { + meta.maintainers = with lib.maintainers; [ tmarkus ]; + + options.programs.pyenv = { + enable = lib.mkEnableOption "pyenv"; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.pyenv; + defaultText = lib.literalExpression "pkgs.pyenv"; + description = "The package to use for pyenv."; + }; + + enableBashIntegration = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to enable pyenv's Bash integration. + ''; + }; + + enableZshIntegration = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to enable pyenv's Zsh integration. + ''; + }; + + enableFishIntegration = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to enable pyenv's Fish integration. + ''; + }; + + rootDirectory = lib.mkOption { + type = lib.types.path; + apply = toString; + default = "${config.xdg.dataHome}/pyenv"; + defaultText = "\${config.xdg.dataHome}/pyenv"; + description = '' + The pyenv root directory (PYENV_ROOT). + + Note: Deviating from upstream which uses `$HOME/.pyenv`, + the default path is set according to the XDG base directory specification. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + # Always add the configured `pyenv` package. + home.packages = [ cfg.package ]; + + programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration '' + export PYENV_ROOT="${cfg.rootDirectory}" + eval "$(${lib.getExe cfg.package} init - bash)" + ''; + + programs.zsh.initExtra = lib.mkIf cfg.enableZshIntegration '' + export PYENV_ROOT="${cfg.rootDirectory}" + eval "$(${lib.getExe cfg.package} init - zsh)" + ''; + + programs.fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration '' + set -Ux PYENV_ROOT "${cfg.rootDirectory}" + ${lib.getExe cfg.package} init - fish | source + ''; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 738b158b2..c21b4b7e6 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -117,6 +117,7 @@ import nmt { ./modules/programs/pls ./modules/programs/powerline-go ./modules/programs/pubs + ./modules/programs/pyenv ./modules/programs/qutebrowser ./modules/programs/readline ./modules/programs/ripgrep diff --git a/tests/modules/programs/pyenv/bash.nix b/tests/modules/programs/pyenv/bash.nix new file mode 100644 index 000000000..ac6a8f0c1 --- /dev/null +++ b/tests/modules/programs/pyenv/bash.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + programs = { + bash.enable = true; + pyenv.enable = true; + }; + + test.stubs.pyenv = { name = "pyenv"; }; + + nmt.script = '' + assertFileExists home-files/.bashrc + assertFileContains \ + home-files/.bashrc \ + 'eval "$(@pyenv@/bin/pyenv init - bash)"' + ''; +} diff --git a/tests/modules/programs/pyenv/default.nix b/tests/modules/programs/pyenv/default.nix new file mode 100644 index 000000000..c2e650587 --- /dev/null +++ b/tests/modules/programs/pyenv/default.nix @@ -0,0 +1,5 @@ +{ + pyenv-bash = ./bash.nix; + pyenv-zsh = ./zsh.nix; + pyenv-fish = ./fish.nix; +} diff --git a/tests/modules/programs/pyenv/fish.nix b/tests/modules/programs/pyenv/fish.nix new file mode 100644 index 000000000..41b4911bb --- /dev/null +++ b/tests/modules/programs/pyenv/fish.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + programs = { + fish.enable = true; + pyenv.enable = true; + }; + + test.stubs.pyenv = { name = "pyenv"; }; + + nmt.script = '' + assertFileExists home-files/.config/fish/config.fish + assertFileContains \ + home-files/.config/fish/config.fish \ + '@pyenv@/bin/pyenv init - fish | source' + ''; +} diff --git a/tests/modules/programs/pyenv/zsh.nix b/tests/modules/programs/pyenv/zsh.nix new file mode 100644 index 000000000..da029fc2c --- /dev/null +++ b/tests/modules/programs/pyenv/zsh.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + programs = { + zsh.enable = true; + pyenv.enable = true; + }; + + test.stubs.pyenv = { name = "pyenv"; }; + + nmt.script = '' + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + 'eval "$(@pyenv@/bin/pyenv init - zsh)"' + ''; +} From 98282a481df50d357e9cbfa7e6a6d481df37e8c2 Mon Sep 17 00:00:00 2001 From: Anton Plotnikov Date: Fri, 7 Jul 2023 10:15:43 +0200 Subject: [PATCH 16/21] swayosd: add module --- modules/misc/news.nix | 8 +++ modules/modules.nix | 1 + modules/services/swayosd.nix | 58 ++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/services/swayosd/default.nix | 1 + tests/modules/services/swayosd/swayosd.nix | 35 +++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 modules/services/swayosd.nix create mode 100644 tests/modules/services/swayosd/default.nix create mode 100644 tests/modules/services/swayosd/swayosd.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 4b432dfaf..6d8a4003c 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1157,6 +1157,14 @@ in A new module is available: 'programs.pyenv'. ''; } + + { + time = "2023-07-08T09:44:56+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.swayosd' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 8822eeed8..a77b75e60 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -312,6 +312,7 @@ let ./services/stalonetray.nix ./services/status-notifier-watcher.nix ./services/swayidle.nix + ./services/swayosd.nix ./services/sxhkd.nix ./services/syncthing.nix ./services/systembus-notify.nix diff --git a/modules/services/swayosd.nix b/modules/services/swayosd.nix new file mode 100644 index 000000000..067c104c3 --- /dev/null +++ b/modules/services/swayosd.nix @@ -0,0 +1,58 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.swayosd; + +in { + meta.maintainers = [ hm.maintainers.pltanton ]; + + options.services.swayosd = { + enable = mkEnableOption '' + swayosd, a GTK based on screen display for keyboard shortcuts like + caps-lock and volume''; + + package = mkPackageOption pkgs "swayosd" { }; + + maxVolume = mkOption { + type = types.nullOr types.ints.unsigned; + default = null; + example = 120; + description = '' + Sets the maximum volume. + ''; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (hm.assertions.assertPlatform "services.swayosd" pkgs platforms.linux) + ]; + + home.packages = [ cfg.package ]; + + systemd.user = { + services.swayosd = { + Unit = { + Description = "Volume/backlight OSD indicator"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session.target" ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; + Documentation = "man:swayosd(1)"; + }; + + Service = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/swayosd" + + (optionalString (cfg.maxVolume != null) + " --max-volume ${toString cfg.maxVolume}"); + Restart = "always"; + }; + + Install = { WantedBy = [ "graphical-session.target" ]; }; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index c21b4b7e6..2fe309895 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -222,6 +222,7 @@ import nmt { ./modules/services/redshift-gammastep ./modules/services/screen-locker ./modules/services/swayidle + ./modules/services/swayosd ./modules/services/sxhkd ./modules/services/syncthing/linux ./modules/services/trayer diff --git a/tests/modules/services/swayosd/default.nix b/tests/modules/services/swayosd/default.nix new file mode 100644 index 000000000..c327610a9 --- /dev/null +++ b/tests/modules/services/swayosd/default.nix @@ -0,0 +1 @@ +{ swayosd = ./swayosd.nix; } diff --git a/tests/modules/services/swayosd/swayosd.nix b/tests/modules/services/swayosd/swayosd.nix new file mode 100644 index 000000000..b371d86ad --- /dev/null +++ b/tests/modules/services/swayosd/swayosd.nix @@ -0,0 +1,35 @@ +{ config, ... }: + +{ + services.swayosd = { + enable = true; + package = config.lib.test.mkStubPackage { + name = "swayosd"; + outPath = "@swayosd@"; + }; + maxVolume = 10; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/systemd/user/swayosd.service \ + ${ + builtins.toFile "swayosd.service" '' + [Install] + WantedBy=graphical-session.target + + [Service] + ExecStart=@swayosd@/bin/swayosd --max-volume 10 + Restart=always + Type=simple + + [Unit] + After=graphical-session.target + ConditionEnvironment=WAYLAND_DISPLAY + Description=Volume/backlight OSD indicator + Documentation=man:swayosd(1) + PartOf=graphical-session.target + '' + } + ''; +} From 24805d3ca73f7d4c34239efaa1c73d2d4558a8ea Mon Sep 17 00:00:00 2001 From: SiriusStarr <2049163+SiriusStarr@users.noreply.github.com> Date: Mon, 3 Jul 2023 11:30:11 -0700 Subject: [PATCH 17/21] himalaya: fix notmuch backend Previously, IMAP was preferred over notmuch, even if notmuch was configured, causing problems with setting account flavor (which automatically sets IMAP settings). The new backend order is: notmuch > IMAP > maildir This also fixes the notmuch DB path being set to the wrong location. The notmuch DB is located at the maildir base path, not in each account's maildir. --- modules/programs/himalaya.nix | 16 ++++++++++------ .../himalaya/notmuch-sendmail-expected.toml | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix index 1a57ec893..673bd7de5 100644 --- a/modules/programs/himalaya.nix +++ b/modules/programs/himalaya.nix @@ -8,14 +8,18 @@ let # attrs util that removes entries containing a null value compactAttrs = lib.filterAttrs (_: val: !isNull val); + # Needed for notmuch config, because the DB is here, and not in each account's dir + maildirBasePath = config.accounts.email.maildirBasePath; + # make a himalaya config from a home-manager email account config mkAccountConfig = _: account: let - imapEnabled = !isNull account.imap; - maildirEnabled = !imapEnabled && !isNull account.maildir - && !account.notmuch.enable; - notmuchEnabled = !imapEnabled && !isNull account.maildir - && account.notmuch.enable; + # Use notmuch if it's enabled, otherwise fallback to IMAP then maildir + # Maildir is always set, so there's no easy way to detect if it's being used + notmuchEnabled = account.notmuch.enable; + imapEnabled = !isNull account.imap && !notmuchEnabled; + maildirEnabled = !isNull account.maildir && !imapEnabled + && !notmuchEnabled; globalConfig = { email = account.address; @@ -55,7 +59,7 @@ let notmuchConfig = lib.optionalAttrs notmuchEnabled (compactAttrs { backend = "notmuch"; - notmuch-db-path = account.maildir.absPath; + notmuch-db-path = maildirBasePath; }); smtpConfig = lib.optionalAttrs (!isNull account.smtp) (compactAttrs { diff --git a/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml b/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml index 1eaa511ba..fcc00c7c8 100644 --- a/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml +++ b/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml @@ -5,7 +5,7 @@ backend = "notmuch" default = true display-name = "H. M. Test" email = "hm@example.com" -notmuch-db-path = "/home/hm-user/Maildir/hm@example.com" +notmuch-db-path = "/home/hm-user/Maildir" sender = "sendmail" sendmail-cmd = "msmtp" From e15010ee6e9bd356a6746ff9b9f9a9097ee8ddcf Mon Sep 17 00:00:00 2001 From: SaiProton Date: Mon, 20 Mar 2023 17:07:24 -0400 Subject: [PATCH 18/21] nushell: add login.nu configuration option Nushell has the option to source from the login.nu file in the case that nushell is used as a login shell. This commit adds the login file alongside the existing config and env files as another configuration option. --- modules/programs/nushell.nix | 31 +++++++++++++++++++ .../programs/nushell/example-settings.nix | 10 ++++++ .../programs/nushell/login-expected.nu | 5 +++ 3 files changed, 46 insertions(+) create mode 100644 tests/modules/programs/nushell/login-expected.nu diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix index a977bd4a6..b72cbb692 100644 --- a/modules/programs/nushell.nix +++ b/modules/programs/nushell.nix @@ -96,6 +96,23 @@ in { ''; }; + loginFile = mkOption { + type = types.nullOr (linesOrSource "login.nu"); + default = null; + example = '' + # Prints "Hello, World" upon logging into tty1 + if (tty) == "/dev/tty1" { + echo "Hello, World" + } + ''; + description = '' + The login file to be used for nushell upon logging in. + + + See for more information. + ''; + }; + extraConfig = mkOption { type = types.lines; default = ""; @@ -112,6 +129,14 @@ in { ''; }; + extraLogin = mkOption { + type = types.lines; + default = ""; + description = '' + Additional configuration to add to the nushell login file. + ''; + }; + shellAliases = mkOption { type = types.attrsOf types.str; default = { }; @@ -161,6 +186,12 @@ in { envVarsStr ]; }) + (mkIf (cfg.loginFile != null || cfg.extraLogin != "") { + "${configDir}/login.nu".text = mkMerge [ + (mkIf (cfg.loginFile != null) cfg.loginFile.text) + cfg.extraLogin + ]; + }) ]; }; } diff --git a/tests/modules/programs/nushell/example-settings.nix b/tests/modules/programs/nushell/example-settings.nix index d8cb01a72..7259db6d3 100644 --- a/tests/modules/programs/nushell/example-settings.nix +++ b/tests/modules/programs/nushell/example-settings.nix @@ -16,6 +16,13 @@ let-env FOO = 'BAR' ''; + loginFile.text = '' + # Prints "Hello, World" upon logging into tty1 + if (tty) == "/dev/tty1" { + echo "Hello, World" + } + ''; + shellAliases = { "lsname" = "(ls | get name)"; "ll" = "ls -a"; @@ -38,5 +45,8 @@ assertFileContent \ "${configDir}/env.nu" \ ${./env-expected.nu} + assertFileContent \ + "${configDir}/login.nu" \ + ${./login-expected.nu} ''; } diff --git a/tests/modules/programs/nushell/login-expected.nu b/tests/modules/programs/nushell/login-expected.nu new file mode 100644 index 000000000..9c21789df --- /dev/null +++ b/tests/modules/programs/nushell/login-expected.nu @@ -0,0 +1,5 @@ +# Prints "Hello, World" upon logging into tty1 +if (tty) == "/dev/tty1" { + echo "Hello, World" +} + From 86157256d2e0d257c53eefeb008230f043e12210 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 9 Jul 2023 03:59:30 +0000 Subject: [PATCH 19/21] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:nixos/nixpkgs/4bc72cae107788bf3f24f30db2e2f685c9298dc9' (2023-06-29) → 'github:nixos/nixpkgs/3c7487575d9445185249a159046cc02ff364bff8' (2023-07-06) --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index b411a332e..74b2c113f 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1688049487, - "narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=", + "lastModified": 1688679045, + "narHash": "sha256-t3xGEfYIwhaLTPU8FLtN/pLPytNeDwbLI6a7XFFBlGo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9", + "rev": "3c7487575d9445185249a159046cc02ff364bff8", "type": "github" }, "original": { From fad475553ae2de3ba1dbcab980698ac070d04e72 Mon Sep 17 00:00:00 2001 From: David Baynard Date: Fri, 7 Jul 2023 23:08:00 +0100 Subject: [PATCH 20/21] imapnotify: use direct nix store path for config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As pointed out in #3291, using the XDG symlink means the agent/unit files don’t change when the contents of the config changes, and so the service will not be restarted. --- modules/services/imapnotify.nix | 13 +++++-------- tests/modules/programs/goimapnotify/launchd.nix | 5 +++-- tests/modules/programs/goimapnotify/launchd.plist | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/services/imapnotify.nix b/modules/services/imapnotify.nix index 048e80974..bc595ca95 100644 --- a/modules/services/imapnotify.nix +++ b/modules/services/imapnotify.nix @@ -21,10 +21,9 @@ let Unit = { Description = "imapnotify for ${name}"; }; Service = { + # Use the nix store path for config to ensure service restarts when it changes ExecStart = - "${getExe cfg.package} -conf '${config.xdg.configHome}/imapnotify/${ - configName account - }'"; + "${getExe cfg.package} -conf '${genAccountConfig account}'"; Restart = "always"; RestartSec = 30; Type = "simple"; @@ -44,11 +43,9 @@ let value = { enable = true; config = { - ProgramArguments = [ - "${getExe cfg.package}" - "-conf" - "${config.xdg.configHome}/imapnotify/${configName account}" - ]; + # Use the nix store path for config to ensure service restarts when it changes + ProgramArguments = + [ "${getExe cfg.package}" "-conf" "${genAccountConfig account}" ]; KeepAlive = true; ThrottleInterval = 30; ExitTimeOut = 0; diff --git a/tests/modules/programs/goimapnotify/launchd.nix b/tests/modules/programs/goimapnotify/launchd.nix index 3d4eca244..5502ebbfc 100644 --- a/tests/modules/programs/goimapnotify/launchd.nix +++ b/tests/modules/programs/goimapnotify/launchd.nix @@ -33,8 +33,9 @@ with lib; nmt.script = let serviceFileName = "org.nix-community.home.imapnotify-hm-example.com.plist"; in '' - serviceFile=LaunchAgents/${serviceFileName} + serviceFile="LaunchAgents/${serviceFileName}" + serviceFileNormalized="$(normalizeStorePaths "$serviceFile")" assertFileExists $serviceFile - assertFileContent $serviceFile ${./launchd.plist} + assertFileContent $serviceFileNormalized ${./launchd.plist} ''; } diff --git a/tests/modules/programs/goimapnotify/launchd.plist b/tests/modules/programs/goimapnotify/launchd.plist index f8e45e8a3..75009bb67 100644 --- a/tests/modules/programs/goimapnotify/launchd.plist +++ b/tests/modules/programs/goimapnotify/launchd.plist @@ -19,7 +19,7 @@ @goimapnotify@/bin/goimapnotify -conf - /home/hm-user/.config/imapnotify/imapnotify-hm-example.com-config.json + /nix/store/00000000000000000000000000000000-imapnotify-hm-example.com-config.json RunAtLoad From b70db52ff06f30e3de7f21b6ea47e75baa0c46f6 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 9 Jul 2023 09:34:18 +0200 Subject: [PATCH 21/21] imapnotify: move test Also add test for the systemd service. --- tests/default.nix | 3 +- .../modules/programs/goimapnotify/default.nix | 1 - .../services/imapnotify-darwin/default.nix | 1 + .../imapnotify-darwin}/launchd.nix | 0 .../imapnotify-darwin}/launchd.plist | 0 tests/modules/services/imapnotify/default.nix | 1 + .../services/imapnotify/imapnotify.nix | 39 +++++++++++++++++++ .../services/imapnotify/imapnotify.service | 12 ++++++ 8 files changed, 55 insertions(+), 2 deletions(-) delete mode 100644 tests/modules/programs/goimapnotify/default.nix create mode 100644 tests/modules/services/imapnotify-darwin/default.nix rename tests/modules/{programs/goimapnotify => services/imapnotify-darwin}/launchd.nix (100%) rename tests/modules/{programs/goimapnotify => services/imapnotify-darwin}/launchd.plist (100%) create mode 100644 tests/modules/services/imapnotify/default.nix create mode 100644 tests/modules/services/imapnotify/imapnotify.nix create mode 100644 tests/modules/services/imapnotify/imapnotify.service diff --git a/tests/default.nix b/tests/default.nix index 2fe309895..890264030 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -146,8 +146,8 @@ import nmt { ./modules/xresources ] ++ lib.optionals isDarwin [ ./modules/launchd + ./modules/services/imapnotify-darwin ./modules/targets-darwin - ./modules/programs/goimapnotify ] ++ lib.optionals isLinux [ ./modules/config/i18n ./modules/i18n/input-method @@ -205,6 +205,7 @@ import nmt { ./modules/services/gpg-agent ./modules/services/gromit-mpx ./modules/services/home-manager-auto-upgrade + ./modules/services/imapnotify ./modules/services/kanshi ./modules/services/lieer ./modules/services/mopidy diff --git a/tests/modules/programs/goimapnotify/default.nix b/tests/modules/programs/goimapnotify/default.nix deleted file mode 100644 index a2adc553d..000000000 --- a/tests/modules/programs/goimapnotify/default.nix +++ /dev/null @@ -1 +0,0 @@ -{ goimapnotify-launchd = ./launchd.nix; } diff --git a/tests/modules/services/imapnotify-darwin/default.nix b/tests/modules/services/imapnotify-darwin/default.nix new file mode 100644 index 000000000..a722604d7 --- /dev/null +++ b/tests/modules/services/imapnotify-darwin/default.nix @@ -0,0 +1 @@ +{ imapnotify-launchd = ./launchd.nix; } diff --git a/tests/modules/programs/goimapnotify/launchd.nix b/tests/modules/services/imapnotify-darwin/launchd.nix similarity index 100% rename from tests/modules/programs/goimapnotify/launchd.nix rename to tests/modules/services/imapnotify-darwin/launchd.nix diff --git a/tests/modules/programs/goimapnotify/launchd.plist b/tests/modules/services/imapnotify-darwin/launchd.plist similarity index 100% rename from tests/modules/programs/goimapnotify/launchd.plist rename to tests/modules/services/imapnotify-darwin/launchd.plist diff --git a/tests/modules/services/imapnotify/default.nix b/tests/modules/services/imapnotify/default.nix new file mode 100644 index 000000000..f3a725dd0 --- /dev/null +++ b/tests/modules/services/imapnotify/default.nix @@ -0,0 +1 @@ +{ imapnotify = ./imapnotify.nix; } diff --git a/tests/modules/services/imapnotify/imapnotify.nix b/tests/modules/services/imapnotify/imapnotify.nix new file mode 100644 index 000000000..c607c042c --- /dev/null +++ b/tests/modules/services/imapnotify/imapnotify.nix @@ -0,0 +1,39 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + imap.port = 993; + + imapnotify = { + enable = true; + boxes = [ "Inbox" ]; + onNotify = '' + ${pkgs.notmuch}/bin/notmuch new + ''; + }; + }; + }; + + services.imapnotify = { + enable = true; + package = (config.lib.test.mkStubPackage { + name = "goimapnotify"; + outPath = "@goimapnotify@"; + }); + }; + + test.stubs.notmuch = { }; + + nmt.script = '' + serviceFile="home-files/.config/systemd/user/imapnotify-hm-example.com.service" + serviceFileNormalized="$(normalizeStorePaths "$serviceFile")" + assertFileExists $serviceFile + assertFileContent $serviceFileNormalized ${./imapnotify.service} + ''; +} diff --git a/tests/modules/services/imapnotify/imapnotify.service b/tests/modules/services/imapnotify/imapnotify.service new file mode 100644 index 000000000..3e3bd9ff6 --- /dev/null +++ b/tests/modules/services/imapnotify/imapnotify.service @@ -0,0 +1,12 @@ +[Install] +WantedBy=default.target + +[Service] +Environment=NOTMUCH_CONFIG=/home/hm-user/.config/notmuch/default/config +ExecStart=@goimapnotify@/bin/goimapnotify -conf '/nix/store/00000000000000000000000000000000-imapnotify-hm-example.com-config.json' +Restart=always +RestartSec=30 +Type=simple + +[Unit] +Description=imapnotify for hm-example.com