mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-30 22:57:55 +00:00
lib: init builder for XDG desktop entry
This commit is contained in:
parent
7e025bd9cf
commit
8138f70d44
@ -39,4 +39,33 @@
|
|||||||
text = lib.generators.toINI { } config;
|
text = lib.generators.toINI { } config;
|
||||||
destination = "/share/xdg-desktop-portal/${lib.optionalString (desktopName != "common") "${desktopName}-"}portals.conf";
|
destination = "/share/xdg-desktop-portal/${lib.optionalString (desktopName != "common") "${desktopName}-"}portals.conf";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Create an XDG desktop entry file. Unlike the `makeDesktopItem`, it doesn't
|
||||||
|
have a required schema as long as it is valid data to be converted to.
|
||||||
|
Furthermore, the validation process can be disabled in case you want to
|
||||||
|
create something like an entry for a desktop session.
|
||||||
|
*/
|
||||||
|
makeXDGDesktopEntry = {
|
||||||
|
name,
|
||||||
|
config,
|
||||||
|
validate ? true,
|
||||||
|
destination ? "/share/applications/${name}.desktop",
|
||||||
|
}:
|
||||||
|
pkgs.writeTextFile {
|
||||||
|
name = "xdg-desktop-entry-${name}";
|
||||||
|
text = lib.generators.toINI {
|
||||||
|
listsAsDuplicateKeys = false;
|
||||||
|
mkKeyValue = lib.generators.mkKeyValueDefault {
|
||||||
|
mkValueString = v:
|
||||||
|
if lib.isList v then lib.concatStringsSep ";" v
|
||||||
|
else lib.generators.mkValueStringDefault { } v;
|
||||||
|
} "=";
|
||||||
|
} config;
|
||||||
|
inherit destination;
|
||||||
|
checkPhase =
|
||||||
|
lib.optionalString validate
|
||||||
|
''
|
||||||
|
${lib.getExe' pkgs.desktop-file-utils "desktop-file-validate"} "$target"
|
||||||
|
'';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -64,4 +64,42 @@ lib.runTests {
|
|||||||
expected =
|
expected =
|
||||||
builtins.readFile ./data/fixtures/xdg-portal.conf;
|
builtins.readFile ./data/fixtures/xdg-portal.conf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# We're just testing out if the destination is correct at this point.
|
||||||
|
testsBuilderMakeSampleXDGDesktopEntry = {
|
||||||
|
expr =
|
||||||
|
let
|
||||||
|
xdgDesktopEntry = self.builders.makeXDGDesktopEntry {
|
||||||
|
name = sampleDesktopName;
|
||||||
|
validate = false;
|
||||||
|
config = {
|
||||||
|
"Desktop Entry".Exec = "Hello";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.readFile "${xdgDesktopEntry}/share/applications/${sampleDesktopName}.desktop";
|
||||||
|
expected =
|
||||||
|
builtins.readFile ./data/fixtures/xdg-desktop-entry.desktop;
|
||||||
|
};
|
||||||
|
|
||||||
|
# We're just testing out if the destination is correct at this point.
|
||||||
|
testsBuilderMakeSampleDesktopSessionFile = {
|
||||||
|
expr =
|
||||||
|
let
|
||||||
|
xdgDesktopEntry = self.builders.makeXDGDesktopEntry {
|
||||||
|
name = sampleDesktopName;
|
||||||
|
validate = false;
|
||||||
|
destination = "/share/wayland-sessions/${sampleDesktopName}.desktop";
|
||||||
|
config = {
|
||||||
|
"Desktop Entry" = {
|
||||||
|
Exec = "Hello";
|
||||||
|
DesktopNames = [ "GNOME" "Sway" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.readFile "${xdgDesktopEntry}/share/wayland-sessions/${sampleDesktopName}.desktop";
|
||||||
|
expected =
|
||||||
|
builtins.readFile ./data/fixtures/xdg-desktop-session.desktop;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
2
tests/lib/data/fixtures/xdg-desktop-entry.desktop
Normal file
2
tests/lib/data/fixtures/xdg-desktop-entry.desktop
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Exec=Hello
|
3
tests/lib/data/fixtures/xdg-desktop-session.desktop
Normal file
3
tests/lib/data/fixtures/xdg-desktop-session.desktop
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
DesktopNames=GNOME;Sway
|
||||||
|
Exec=Hello
|
Loading…
Reference in New Issue
Block a user