lib: add functions for creating NixOS-like environments

This commit is contained in:
Gabriel Arazas 2024-07-06 15:25:18 +08:00
parent 6fd2e28370
commit 4d32203d4d
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360

View File

@ -11,4 +11,34 @@
# Checks if the NixOS config is being built for a particular format. # Checks if the NixOS config is being built for a particular format.
isFormat = config: format: isFormat = config: format:
(config.formatAttr or "") == format; (config.formatAttr or "") == format;
# Create a separate environment similar to NixOS `system.path`. This is
# typically used to create isolated environments for custom desktop sessions
# which makes it possible to have them installed side-by-side with their own
# set of applications and everything (except for overlapping NixOS services
# that will just add them into the NixOS environment itself).
mkNixoslikeEnvironment = config: args:
pkgs.buildEnv {
inherit (args) paths name;
inherit (config.environment) pathsToLink extraOutputsToInstall;
ignoreCollisions = true;
postBuild =
''
# Remove wrapped binaries, they shouldn't be accessible via PATH.
find $out/bin -maxdepth 1 -name ".*-wrapped" -type l -delete
if [ -x $out/bin/glib-compile-schemas -a -w $out/share/glib-2.0/schemas ]; then
$out/bin/glib-compile-schemas $out/share/glib-2.0/schemas
fi
${config.environment.extraSetup}
'';
};
# Given an environment (built with `pkgs.buildEnv`), create a systemd
# environment attrset meant to be used as part of the desktop service.
mkSystemdDesktopEnvironment = env: {
XDG_DATA_DIRS = "${env}/share\${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}";
XDG_CONFIG_DIRS = "${env}/etc/xdg\${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS}";
};
} }