Browse Source

Basic environment variable support

Signed-off-by: Magic_RB <magic_rb@redalder.org>
master
Magic_RB 3 weeks ago
parent
commit
1303718029
Signed by: Magic_RB GPG Key ID: 08D5287CC5DDCA0E
4 changed files with 64 additions and 3 deletions
  1. +1
    -0
      lib/make-system.nix
  2. +44
    -0
      modules/environment.nix
  3. +17
    -3
      modules/nix.nix
  4. +2
    -0
      todos.org

+ 1
- 0
lib/make-system.nix View File

@ -15,6 +15,7 @@ let
../modules/bootloader
../modules/nix.nix
../modules/environment.nix
../modules/users.nix
../modules/ids.nix


+ 44
- 0
modules/environment.nix View File

@ -0,0 +1,44 @@
{ pkgs, lib, config, nglib, ... }:
with lib;
let
cfg = config.environment;
profileScript = pkgs.writeShellScript "profile" cfg.shell.profile;
in
{
options.environment = {
variables = mkOption {
default = {};
example = { EDITOR = "vim"; BROWSER = "firefox"; };
type = with types; attrsOf (either str (listOf str));
apply = x: concatStringsSep ":"
(mapAttrsToList (n: v: "${n}=" + (if isList v then concatStringsSep ":" v else v)) x);
};
shell = {
profile = mkOption {
description = ''
Shell script fragments, concataned into /etc/profile.
'';
type = with types; listOf str;
apply = x: concatStringsSep "\n" x;
default = [];
};
};
};
config = {
environment.shell.profile =[
''
export ${cfg.variables}
''
];
system.activation.shellProfile = nglib.dag.dagEntryAnywhere ''
export PATH=${pkgs.busybox}/bin
mkdir -m 0755 -p /etc
ln -sfn ${profileScript} /etc/.profile.tmp
mv /etc/.profile.tmp /etc/profile # atomically replace /etc/profile
'';
};
}

+ 17
- 3
modules/nix.nix View File

@ -16,7 +16,7 @@ in
default = pkgs.nix;
};
buildUserCound = mkOption {
buildUserCount = mkOption {
description = ''
How many build users, and groups should be created, if Nix runs out,
increase this number.
@ -25,6 +25,16 @@ in
default = 32;
};
nixPath = mkOption {
description = ''
The Nix Path, basically channels.
'';
type = with types; listOf str;
default = [
"nixpkgs=${pkgs.path}"
];
};
readOnlyStore = mkOption {
description = ''
Whether the store should be made read-only by using a bind mount.
@ -80,15 +90,19 @@ in
uid = 30000 + x;
group = "nixbld";
home = "/var/empty";
createHome = false;
description = "Nix build user ${toString x}";
shell = "${pkgs.busybox}/bin/nologin";
};
})
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25 26 27 28 29 30 31 32 ]);
(range 0 cfg.buildUserCount));
groups.nixbld.gid = 30000;
};
environment.variables = {
NIX_PATH = cfg.nixPath;
};
};
}

+ 2
- 0
todos.org View File

@ -0,0 +1,2 @@
* TODO allow overriding the default packages, in ~nix.nixPath~, by creating ~nixpkgs.pkgs~

Loading…
Cancel
Save