diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6b0f08dfa..470e8d27c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -64,6 +64,9 @@ /modules/programs/firefox.nix @rycee +/modules/programs/foot.nix @plabadens +/tests/modules/programs/foot @plabadens + /modules/programs/gh.nix @Gerschtli /tests/modules/programs/gh @Gerschtli diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 270454a5b..d92cae810 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2021,6 +2021,14 @@ in for discussion. ''; } + + { + time = "2021-05-18T20:28:50+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'programs.foot'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 573764b3f..e7f4c1b63 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -68,6 +68,7 @@ let (loadModule ./programs/feh.nix { }) (loadModule ./programs/firefox.nix { }) (loadModule ./programs/fish.nix { }) + (loadModule ./programs/foot.nix { condition = hostPlatform.isLinux; }) (loadModule ./programs/fzf.nix { }) (loadModule ./programs/getmail.nix { condition = hostPlatform.isLinux; }) (loadModule ./programs/gh.nix { }) diff --git a/modules/programs/foot.nix b/modules/programs/foot.nix new file mode 100644 index 000000000..8df201fd9 --- /dev/null +++ b/modules/programs/foot.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.foot; + iniFormat = pkgs.formats.ini { }; + +in { + meta.maintainers = with lib.maintainers; [ plabadens ]; + + options.programs.foot = { + enable = mkEnableOption "Foot terminal"; + + package = mkOption { + type = types.package; + default = pkgs.foot; + defaultText = literalExample "pkgs.foot"; + description = "The foot package to install"; + }; + + server.enable = mkEnableOption "Foot terminal server"; + + settings = mkOption { + type = iniFormat.type; + default = { }; + description = '' + Configuration written to + $XDG_CONFIG_HOME/foot/foot.ini. See + for a list of available options. + ''; + example = literalExample '' + { + main = { + term = "xterm-256color"; + + font = "Fira Code:size=11"; + dpi-aware = "yes"; + }; + + mouse = { + hide-when-typing = "yes"; + }; + } + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."foot/foot.ini" = mkIf (cfg.settings != { }) { + source = iniFormat.generate "foot.ini" cfg.settings; + }; + + systemd.user.services = mkIf cfg.server.enable { + foot = { + Unit = { + Description = + "Fast, lightweight and minimalistic Wayland terminal emulator."; + Documentation = "man:foot(1)"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session.target" ]; + }; + + Service = { + ExecStart = "${cfg.package}/bin/foot --server"; + Restart = "on-failure"; + }; + + Install = { WantedBy = [ "graphical-session.target" ]; }; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index e186ba816..62bb3de3c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -96,6 +96,7 @@ import nmt { ./modules/programs/abook ./modules/programs/autorandr ./modules/programs/firefox + ./modules/programs/foot ./modules/programs/getmail ./modules/programs/i3status-rust ./modules/programs/ncmpcpp-linux diff --git a/tests/modules/programs/foot/default.nix b/tests/modules/programs/foot/default.nix new file mode 100644 index 000000000..329e0f1f2 --- /dev/null +++ b/tests/modules/programs/foot/default.nix @@ -0,0 +1,5 @@ +{ + foot-example-settings = ./example-settings.nix; + foot-empty-settings = ./empty-settings.nix; + foot-systemd-user-service = ./systemd-user-service.nix; +} diff --git a/tests/modules/programs/foot/empty-settings.nix b/tests/modules/programs/foot/empty-settings.nix new file mode 100644 index 000000000..3935fd9dc --- /dev/null +++ b/tests/modules/programs/foot/empty-settings.nix @@ -0,0 +1,16 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.foot.enable = true; + + nixpkgs.overlays = + [ (self: super: { foot = pkgs.writeScriptBin "dummy-foot" ""; }) ]; + + nmt.script = '' + assertPathNotExists home-files/.config/foot + ''; + }; +} diff --git a/tests/modules/programs/foot/example-settings-expected.ini b/tests/modules/programs/foot/example-settings-expected.ini new file mode 100644 index 000000000..f5e12d80b --- /dev/null +++ b/tests/modules/programs/foot/example-settings-expected.ini @@ -0,0 +1,7 @@ +[main] +dpi-aware=yes +font=Fira Code:size=11 +term=xterm-256color + +[mouse] +hide-when-typing=yes diff --git a/tests/modules/programs/foot/example-settings.nix b/tests/modules/programs/foot/example-settings.nix new file mode 100644 index 000000000..c23063823 --- /dev/null +++ b/tests/modules/programs/foot/example-settings.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.foot = { + enable = true; + package = pkgs.writeShellScriptBin "dummy-foot" ""; + + settings = { + main = { + term = "xterm-256color"; + + font = "Fira Code:size=11"; + dpi-aware = "yes"; + }; + + mouse = { hide-when-typing = "yes"; }; + }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/foot/foot.ini \ + ${./example-settings-expected.ini} + ''; + }; +} diff --git a/tests/modules/programs/foot/systemd-user-service-expected.service b/tests/modules/programs/foot/systemd-user-service-expected.service new file mode 100644 index 000000000..ff0f8a61b --- /dev/null +++ b/tests/modules/programs/foot/systemd-user-service-expected.service @@ -0,0 +1,12 @@ +[Install] +WantedBy=graphical-session.target + +[Service] +ExecStart=@foot@/bin/foot --server +Restart=on-failure + +[Unit] +After=graphical-session.target +Description=Fast, lightweight and minimalistic Wayland terminal emulator. +Documentation=man:foot(1) +PartOf=graphical-session.target diff --git a/tests/modules/programs/foot/systemd-user-service.nix b/tests/modules/programs/foot/systemd-user-service.nix new file mode 100644 index 000000000..1eff14f9f --- /dev/null +++ b/tests/modules/programs/foot/systemd-user-service.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: + +let + package = pkgs.writeShellScriptBin "dummy-foot" "" // { outPath = "@foot@"; }; +in { + config = { + programs.foot = { + inherit package; + enable = true; + server.enable = true; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/foot/foot.ini + + assertFileContent \ + home-files/.config/systemd/user/foot.service \ + ${./systemd-user-service-expected.service} + ''; + }; +}