Skip to content

Commit

Permalink
nixos/system-path-core.nix: Extract module
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Dec 9, 2021
1 parent c8da2d4 commit c6ea188
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 69 deletions.
87 changes: 87 additions & 0 deletions nixos/modules/config/system-path-core.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{ config, lib, pkgs, ... }:
let
inherit (lib)
mkOption
types
literalExpression
;
in
{
options = {

environment = {

systemPackages = mkOption {
type = types.listOf types.package;
default = [ ];
example = literalExpression "[ pkgs.firefox pkgs.htop ]";
description = ''
The set of packages that appear in
/run/current-system/sw. These packages are
automatically available to all users, and are
automatically updated every time you rebuild the system
configuration. (The latter is the main difference with
installing them in the default profile,
<filename>/nix/var/nix/profiles/default</filename>.
'';
};

pathsToLink = mkOption {
type = types.listOf types.str;
# Note: We need `/lib' to be among `pathsToLink' for NSS modules
# to work.
default = [ ];
example = [ "/" ];
description = "List of directories to be symlinked in <filename>/run/current-system/sw</filename>.";
};

extraOutputsToInstall = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "doc" "info" "devdoc" ];
description = "List of additional package outputs to be symlinked into <filename>/run/current-system/sw</filename>.";
};

extraSetup = mkOption {
type = types.lines;
default = "";
description = "Shell fragments to be run after the system environment has been created. This should only be used for things that need to modify the internals of the environment, e.g. generating MIME caches. The environment being built can be accessed at $out.";
};

};

system = {

path = mkOption {
internal = true;
description = ''
The packages you want in the boot environment.
'';
};

};

};
config = {
environment.pathsToLink = [
"/bin"
];

system.path = pkgs.buildEnv {
name = "system-path";
paths = config.environment.systemPackages;
inherit (config.environment) pathsToLink extraOutputsToInstall;
ignoreCollisions = true;
# !!! Hacky, should modularise.
# outputs TODO: note that the tools will often not be linked by default
postBuild =
''
# Remove wrapped binaries, they shouldn't be accessible via PATH.
find $out/bin -maxdepth 1 -name ".*-wrapped" -type l -delete
${config.environment.extraSetup}
'';
};

};
}
77 changes: 8 additions & 69 deletions nixos/modules/config/system-path.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,12 @@ let
in

{
imports = [ ./system-path-core.nix ];

options = {

environment = {

systemPackages = mkOption {
type = types.listOf types.package;
default = [];
example = literalExpression "[ pkgs.firefox pkgs.thunderbird ]";
description = ''
The set of packages that appear in
/run/current-system/sw. These packages are
automatically available to all users, and are
automatically updated every time you rebuild the system
configuration. (The latter is the main difference with
installing them in the default profile,
<filename>/nix/var/nix/profiles/default</filename>.
'';
};

defaultPackages = mkOption {
type = types.listOf types.package;
default = defaultPackages;
Expand All @@ -93,39 +80,6 @@ in
'';
};

pathsToLink = mkOption {
type = types.listOf types.str;
# Note: We need `/lib' to be among `pathsToLink' for NSS modules
# to work.
default = [];
example = ["/"];
description = "List of directories to be symlinked in <filename>/run/current-system/sw</filename>.";
};

extraOutputsToInstall = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "doc" "info" "devdoc" ];
description = "List of additional package outputs to be symlinked into <filename>/run/current-system/sw</filename>.";
};

extraSetup = mkOption {
type = types.lines;
default = "";
description = "Shell fragments to be run after the system environment has been created. This should only be used for things that need to modify the internals of the environment, e.g. generating MIME caches. The environment being built can be accessed at $out.";
};

};

system = {

path = mkOption {
internal = true;
description = ''
The packages you want in the boot environment.
'';
};

};

};
Expand All @@ -135,8 +89,7 @@ in
environment.systemPackages = requiredPackages ++ config.environment.defaultPackages;

environment.pathsToLink =
[ "/bin"
"/etc/xdg"
[ "/etc/xdg"
"/etc/gtk-2.0"
"/etc/gtk-3.0"
"/lib" # FIXME: remove and update debug-info.nix
Expand All @@ -155,25 +108,11 @@ in
"/share/thumbnailers"
];

system.path = pkgs.buildEnv {
name = "system-path";
paths = config.environment.systemPackages;
inherit (config.environment) pathsToLink extraOutputsToInstall;
ignoreCollisions = true;
# !!! Hacky, should modularise.
# outputs TODO: note that the tools will often not be linked by default
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}
'';
};
environment.extraSetup = ''
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
'';

};
}

0 comments on commit c6ea188

Please sign in to comment.