Skip to content

Commit

Permalink
Merge branch 'master' into feat/nix-init
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter committed May 7, 2024
2 parents 2c5ad52 + 6e277d9 commit 753f91c
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 12 deletions.
14 changes: 13 additions & 1 deletion modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,19 @@ in {
}

{
time = "2024-05-05T23:27:20+00:00";
time = "2024-05-06T07:36:13+00:00";
condition = hostPlatform.isLinux;
message = ''
A new module is available: 'programs.gnome-shell'.
GNOME Shell is the graphical shell of the GNOME desktop environment.
It provides basic functions like launching applications and switching
between windows, and is also a widget engine.
'';
}

{
time = "2024-05-07T16:28:55+00:00";
message = ''
A new module is available: 'programs.nix-init'.
'';
Expand Down
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ let
./programs/git-credential-oauth.nix
./programs/git.nix
./programs/gitui.nix
./programs/gnome-shell.nix
./programs/gnome-terminal.nix
./programs/go.nix
./programs/gpg.nix
Expand Down
4 changes: 2 additions & 2 deletions modules/programs/git.nix
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ in {
nameValuePair "sendemail.${name}" (if account.msmtp.enable then {
smtpServer = "${pkgs.msmtp}/bin/msmtp";
envelopeSender = "auto";
from = address;
from = "${realName} <${address}>";
} else
{
smtpEncryption = if smtp.tls.enable then
Expand All @@ -407,7 +407,7 @@ in {
mkIf smtp.tls.enable (toString smtp.tls.certificatesFile);
smtpServer = smtp.host;
smtpUser = userName;
from = address;
from = "${realName} <${address}>";
} // optionalAttrs (smtp.port != null) {
smtpServerPort = smtp.port;
});
Expand Down
115 changes: 115 additions & 0 deletions modules/programs/gnome-shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{ config, lib, pkgs, ... }:

with lib;
let
cfg = config.programs.gnome-shell;

extensionOpts = { config, ... }: {
options = {
id = mkOption {
type = types.str;
example = "user-theme@gnome-shell-extensions.gcampax.github.com";
description = ''
ID of the GNOME Shell extension. If not provided, it
will be obtained from `package.extensionUuid`.
'';
};

package = mkOption {
type = types.package;
example = "pkgs.gnome.gnome-shell-extensions";
description = ''
Package providing a GNOME Shell extension in
`$out/share/gnome-shell/extensions/''${id}`.
'';
};
};

config = mkIf (hasAttr "extensionUuid" config.package) {
id = mkDefault config.package.extensionUuid;
};
};

themeOpts = {
options = {
name = mkOption {
type = types.str;
example = "Plata-Noir";
description = ''
Name of the GNOME Shell theme.
'';
};

package = mkOption {
type = types.nullOr types.package;
default = null;
example = literalExpression "pkgs.plata-theme";
description = ''
Package providing a GNOME Shell theme in
`$out/share/themes/''${name}/gnome-shell`.
'';
};
};
};

in {
meta.maintainers = [ maintainers.terlar ];

options.programs.gnome-shell = {
enable = mkEnableOption "GNOME Shell customization";

extensions = mkOption {
type = types.listOf (types.submodule extensionOpts);
default = [ ];
example = literalExpression ''
[
{ package = pkgs.gnomeExtensions.dash-to-panel; }
{
id = "user-theme@gnome-shell-extensions.gcampax.github.com";
package = pkgs.gnome.gnome-shell-extensions;
}
]
'';
description = ''
List of GNOME Shell extensions.
'';
};

theme = mkOption {
type = types.nullOr (types.submodule themeOpts);
default = null;
example = literalExpression ''
{
name = "Plata-Noir";
package = pkgs.plata-theme;
}
'';
description = ''
Theme to use for GNOME Shell.
'';
};
};

config = mkIf cfg.enable (mkMerge [
(mkIf (cfg.extensions != [ ]) {
dconf.settings."org/gnome/shell" = {
disable-user-extensions = false;
enabled-extensions = catAttrs "id" cfg.extensions;
};

home.packages = catAttrs "package" cfg.extensions;
})

(mkIf (cfg.theme != null) {
dconf.settings."org/gnome/shell/extensions/user-theme".name =
cfg.theme.name;

programs.gnome-shell.extensions = [{
id = "user-theme@gnome-shell-extensions.gcampax.github.com";
package = pkgs.gnome.gnome-shell-extensions;
}];

home.packages = [ cfg.theme.package ];
})
]);
}
22 changes: 21 additions & 1 deletion modules/programs/jujutsu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ in {

package = mkPackageOption pkgs "jujutsu" { };

ediff = mkOption {
type = types.bool;
default = config.programs.emacs.enable;
defaultText = literalExpression "config.programs.emacs.enable";
description = ''
Enable ediff as a merge tool
'';
};

settings = mkOption {
type = tomlFormat.type;
default = { };
Expand All @@ -45,7 +54,18 @@ in {
home.packages = [ cfg.package ];

home.file.".jjconfig.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "jujutsu-config" cfg.settings;
source = tomlFormat.generate "jujutsu-config" (cfg.settings
// optionalAttrs (cfg.ediff) (let
emacsDiffScript = pkgs.writeShellScriptBin "emacs-ediff" ''
set -euxo pipefail
${config.programs.emacs.package}/bin/emacsclient -c --eval "(ediff-merge-files-with-ancestor \"$1\" \"$2\" \"$3\" nil \"$4\")"
'';
in {
merge-tools.ediff = {
program = getExe emacsDiffScript;
merge-args = [ "$left" "$right" "$base" "$output" ];
};
}));
};
};
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ in import nmtSrc {
./modules/programs/freetube
./modules/programs/fuzzel
./modules/programs/getmail
./modules/programs/gnome-shell
./modules/programs/gnome-terminal
./modules/programs/hexchat
./modules/programs/i3blocks
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/programs/git/git-with-email-expected.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[sendemail "hm-account"]
from = "hm@example.org"
from = "H. M. Test Jr. <hm@example.org>"
smtpEncryption = "tls"
smtpServer = "smtp.example.org"
smtpSslCertPath = "/etc/test/certificates.crt"
smtpUser = "home.manager.jr"

[sendemail "hm@example.com"]
from = "hm@example.com"
from = "H. M. Test <hm@example.com>"
smtpEncryption = "ssl"
smtpServer = "smtp.example.com"
smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt"
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/programs/git/git-with-email.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ with lib;
./git-with-email-expected.conf
}
assertGitConfig "sendemail.hm@example.com.from" "hm@example.com"
assertGitConfig "sendemail.hm-account.from" "hm@example.org"
assertGitConfig "sendemail.hm@example.com.from" "H. M. Test <hm@example.com>"
assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. <hm@example.org>"
'';
};
}
4 changes: 2 additions & 2 deletions tests/modules/programs/git/git-with-msmtp-expected.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[sendemail "hm-account"]
from = "hm@example.org"
from = "H. M. Test Jr. <hm@example.org>"
smtpEncryption = "tls"
smtpServer = "smtp.example.org"
smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt"
smtpUser = "home.manager.jr"

[sendemail "hm@example.com"]
envelopeSender = "auto"
from = "hm@example.com"
from = "H. M. Test <hm@example.com>"
smtpServer = "@msmtp@/bin/msmtp"

[user]
Expand Down
5 changes: 3 additions & 2 deletions tests/modules/programs/git/git-with-msmtp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ with lib;

config = {
accounts.email.accounts."hm@example.com".msmtp.enable = true;

programs.git = {
enable = true;
package = pkgs.gitMinimal;
Expand All @@ -33,8 +34,8 @@ with lib;
assertFileContent home-files/.config/git/config \
${./git-with-msmtp-expected.conf}
assertGitConfig "sendemail.hm@example.com.from" "hm@example.com"
assertGitConfig "sendemail.hm-account.from" "hm@example.org"
assertGitConfig "sendemail.hm@example.com.from" "H. M. Test <hm@example.com>"
assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. <hm@example.org>"
assertGitConfig "sendemail.hm@example.com.smtpServer" "${pkgs.msmtp}/bin/msmtp"
assertGitConfig "sendemail.hm@example.com.envelopeSender" "auto"
'';
Expand Down
1 change: 1 addition & 0 deletions tests/modules/programs/gnome-shell/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ gnome-shell = ./gnome-shell.nix; }
94 changes: 94 additions & 0 deletions tests/modules/programs/gnome-shell/gnome-shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{ config, lib, pkgs, ... }:

with lib;

let
dummy-gnome-shell-extensions = pkgs.runCommand "dummy-package" { } ''
mkdir -p $out/share/gnome-shell/extensions/dummy-package
touch $out/share/gnome-shell/extensions/dummy-package/test
'';

test-extension = pkgs.runCommand "test-extension" { } ''
mkdir -p $out/share/gnome-shell/extensions/test-extension
touch $out/share/gnome-shell/extensions/test-extension/test
'';

test-extension-uuid = pkgs.runCommand "test-extension-uuid" {
passthru.extensionUuid = "test-extension-uuid";
} ''
mkdir -p $out/share/gnome-shell/extensions/test-extension-uuid
touch $out/share/gnome-shell/extensions/test-extension-uuid/test
'';

test-theme = pkgs.runCommand "test-theme" { } ''
mkdir -p $out/share/themes/Test/gnome-shell
touch $out/share/themes/Test/gnome-shell/test
'';

expectedEnabledExtensions = [
"user-theme@gnome-shell-extensions.gcampax.github.com"
"test-extension"
"test-extension-uuid"
];

actualEnabledExtensions = catAttrs "value"
config.dconf.settings."org/gnome/shell".enabled-extensions.value;

in {
nixpkgs.overlays = [
(self: super: {
gnome = super.gnome.overrideScope (gself: gsuper: {
gnome-shell-extensions = dummy-gnome-shell-extensions;
});
})
];

programs.gnome-shell.enable = true;

programs.gnome-shell.extensions = [
{
id = "test-extension";
package = test-extension;
}
{ package = test-extension-uuid; }
];

programs.gnome-shell.theme = {
name = "Test";
package = test-theme;
};

assertions = [
{
assertion =
config.dconf.settings."org/gnome/shell".disable-user-extensions
== false;
message = "Expected disable-user-extensions to be false.";
}
{
assertion =
all (e: elem e actualEnabledExtensions) expectedEnabledExtensions;
message = ''
Expected enabled-extensions to contain all of:
${toString expectedEnabledExtensions}
But it was:
${toString actualEnabledExtensions}
'';
}
{
assertion =
config.dconf.settings."org/gnome/shell/extensions/user-theme".name
== "Test";
message = "Expected extensions/user-theme/name to be 'Test'.";
}
];

test.stubs.dconf = { };

nmt.script = ''
assertFileExists home-path/share/gnome-shell/extensions/dummy-package/test
assertFileExists home-path/share/gnome-shell/extensions/test-extension/test
assertFileExists home-path/share/gnome-shell/extensions/test-extension-uuid/test
assertFileExists home-path/share/themes/Test/gnome-shell/test
'';
}

0 comments on commit 753f91c

Please sign in to comment.