mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
lib: init builders subset
Most of it is specifically for NixOS usage but in case that it is possible for independent desktop sessions entirely made in home-manager especially in non-NixOS systems, it will be... nice.
This commit is contained in:
parent
f46cec6e11
commit
11806b9c4b
42
lib/builders.nix
Normal file
42
lib/builders.nix
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
|
{
|
||||||
|
/* Create an XDG MIME Association listing. This should also take care of
|
||||||
|
generating desktop-specific mimeapps.list if `desktopName` is given. The
|
||||||
|
given desktop name is already assumed to be in suitable casing which is
|
||||||
|
typically in lowercase ASCII.
|
||||||
|
*/
|
||||||
|
makeXDGMimeAssociationList = {
|
||||||
|
desktopName ? "",
|
||||||
|
addedAssociations ? { },
|
||||||
|
removedAssociations ? { },
|
||||||
|
defaultApplications ? { },
|
||||||
|
}:
|
||||||
|
pkgs.writeTextFile {
|
||||||
|
name = "xdg-mime-associations";
|
||||||
|
text =
|
||||||
|
# Non-desktop-specific mimeapps.list are only allowed to specify
|
||||||
|
# default applications.
|
||||||
|
lib.generators.toINI { } ({
|
||||||
|
"Default Applications" = defaultApplications;
|
||||||
|
} // (lib.optionalAttrs (desktopName == "") {
|
||||||
|
"Added Associations" = addedAssociations;
|
||||||
|
"Removed Associations" = removedAssociations;
|
||||||
|
}));
|
||||||
|
destination = "/share/applications/${lib.optionalString (desktopName != "") "${desktopName}-"}mimeapps.list";
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Create an XDG Portals configuration with the given desktop name and its
|
||||||
|
configuration. Similarly, the given desktop name is assumed to be already
|
||||||
|
in its suitable form of a lowercase ASCII.
|
||||||
|
*/
|
||||||
|
makeXDGPortalConfiguration = {
|
||||||
|
desktopName ? "common",
|
||||||
|
config,
|
||||||
|
}:
|
||||||
|
pkgs.writeTextFile {
|
||||||
|
name = "xdg-portal-config-${desktopName}";
|
||||||
|
text = lib.generators.toINI { } config;
|
||||||
|
destination = "/share/xdg-desktop-portal/${lib.optionalString (desktopName != "common") "${desktopName}-"}portals.conf";
|
||||||
|
};
|
||||||
|
}
|
@ -12,9 +12,11 @@ pkgs.lib.makeExtensible
|
|||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
callLib = file: import file { inherit pkgs lib self; };
|
callLib = file: import file { inherit pkgs lib self; };
|
||||||
in {
|
in {
|
||||||
|
builders = callLib ./builders.nix;
|
||||||
trivial = callLib ./trivial.nix;
|
trivial = callLib ./trivial.nix;
|
||||||
data = callLib ./data.nix;
|
data = callLib ./data.nix;
|
||||||
|
|
||||||
|
inherit (self.builders) makeXDGMimeAssociationList makeXDGPortalConfiguration;
|
||||||
inherit (self.trivial) countAttrs;
|
inherit (self.trivial) countAttrs;
|
||||||
inherit (self.data) importYAML renderTeraTemplate;
|
inherit (self.data) importYAML renderTeraTemplate;
|
||||||
})
|
})
|
||||||
|
67
tests/lib/builders.nix
Normal file
67
tests/lib/builders.nix
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
|
let
|
||||||
|
sampleDesktopName = "horizontal-hunger";
|
||||||
|
in
|
||||||
|
lib.runTests {
|
||||||
|
testsBuilderMakeSampleXDGAssociationList = {
|
||||||
|
expr =
|
||||||
|
let
|
||||||
|
xdgAssociations = self.builders.makeXDGMimeAssociationList {
|
||||||
|
defaultApplications = {
|
||||||
|
"application/pdf" = "firefox.desktop";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in builtins.readFile "${xdgAssociations}/share/applications/mimeapps.list";
|
||||||
|
expected =
|
||||||
|
builtins.readFile ./data/fixtures/xdg-mime-sample-mimeapps.list;
|
||||||
|
};
|
||||||
|
|
||||||
|
# This should only create the "Default Applications" section of the
|
||||||
|
# specific-desktop mimeapps.list.
|
||||||
|
testsBuilderMakeSampleDesktopSpecificXDGAssociationList = {
|
||||||
|
expr =
|
||||||
|
let
|
||||||
|
xdgAssociations = self.builders.makeXDGMimeAssociationList {
|
||||||
|
desktopName = sampleDesktopName;
|
||||||
|
defaultApplications = {
|
||||||
|
"application/pdf" = "firefox.desktop";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in builtins.readFile "${xdgAssociations}/share/applications/${sampleDesktopName}-mimeapps.list";
|
||||||
|
expected =
|
||||||
|
builtins.readFile ./data/fixtures/xdg-mime-sample-desktop-specific-mimeapps.list;
|
||||||
|
};
|
||||||
|
|
||||||
|
testsBuilderMakeSampleXDGPortalCommonConfig = {
|
||||||
|
expr =
|
||||||
|
let
|
||||||
|
xdgPortalConf = self.builders.makeXDGPortalConfiguration {
|
||||||
|
config.preferred = {
|
||||||
|
default = "gtk";
|
||||||
|
"org.freedesktop.impl.portal.Screencast" = "gnome";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.readFile "${xdgPortalConf}/share/xdg-desktop-portal/portals.conf";
|
||||||
|
expected =
|
||||||
|
builtins.readFile ./data/fixtures/xdg-portal.conf;
|
||||||
|
};
|
||||||
|
|
||||||
|
# We're just testing out if the destination is correct at this point.
|
||||||
|
testsBuilderMakeSampleXDGPortalDesktopSpecificConfig = {
|
||||||
|
expr =
|
||||||
|
let
|
||||||
|
xdgPortalConf = self.builders.makeXDGPortalConfiguration {
|
||||||
|
desktopName = sampleDesktopName;
|
||||||
|
config.preferred = {
|
||||||
|
default = "gtk";
|
||||||
|
"org.freedesktop.impl.portal.Screencast" = "gnome";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.readFile "${xdgPortalConf}/share/xdg-desktop-portal/${sampleDesktopName}-portals.conf";
|
||||||
|
expected =
|
||||||
|
builtins.readFile ./data/fixtures/xdg-portal.conf;
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
[Default Applications]
|
||||||
|
application/pdf=firefox.desktop
|
6
tests/lib/data/fixtures/xdg-mime-sample-mimeapps.list
Normal file
6
tests/lib/data/fixtures/xdg-mime-sample-mimeapps.list
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[Added Associations]
|
||||||
|
|
||||||
|
[Default Applications]
|
||||||
|
application/pdf=firefox.desktop
|
||||||
|
|
||||||
|
[Removed Associations]
|
3
tests/lib/data/fixtures/xdg-portal.conf
Normal file
3
tests/lib/data/fixtures/xdg-portal.conf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[preferred]
|
||||||
|
default=gtk
|
||||||
|
org.freedesktop.impl.portal.Screencast=gnome
|
@ -17,6 +17,7 @@ let
|
|||||||
callLib = file: import file { inherit pkgs lib; self = foodogsquaredLib; };
|
callLib = file: import file { inherit pkgs lib; self = foodogsquaredLib; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
builders = callLib ./builders.nix;
|
||||||
trivial = callLib ./trivial.nix;
|
trivial = callLib ./trivial.nix;
|
||||||
data = callLib ./data;
|
data = callLib ./data;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user