Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
18672bf
lib.nixos: init
roberth Dec 3, 2021
62e7f0e
nixos/nixpkgs.nix: Make independent
roberth Dec 3, 2021
dd6d8e3
pkgs.nixosModule: init
roberth Dec 3, 2021
7f129e3
nixos/build.nix: Make independent
roberth Dec 3, 2021
56c283e
nixos/etc.nix: Make independent
roberth Dec 3, 2021
9b2af86
dockerTools: Add example of using NixOS' etc
roberth Dec 3, 2021
4ec415c
nixos/top-level.nix: Make extensible
roberth Dec 5, 2021
baa96b8
nixos/system-with-activation.nix: Extract module
roberth Dec 5, 2021
8da928c
nixos/bootable.nix: Extract module
roberth Dec 5, 2021
2bf147c
nixos/specialisation.nix: Extract module
roberth Dec 5, 2021
c78d41a
nixos: Move top-level stage2 def to stage-2.nix
roberth Dec 5, 2021
c8da2d4
nixos: Move system.name logic to network-interfaces.nix
roberth Dec 5, 2021
c6ea188
nixos/system-path-core.nix: Extract module
roberth Dec 8, 2021
dc2b396
nixos/users-groups.nix: Make independent
roberth Dec 8, 2021
42b59e3
nixos/update-users-groups.pl: Fall back to root group for shadow
roberth Dec 8, 2021
b9cb182
nixos: Move specialfs activation script to filesystems.nix
roberth Dec 8, 2021
db05855
nixos/top-level.nix: Move configurationName to grub.nix
roberth Dec 8, 2021
8313fd3
nixos/top-level.nix: Make independent of systemd.package
roberth Dec 8, 2021
8772485
nixos/user-profiles.nix: Extract module
roberth Dec 8, 2021
f2cd714
nixos/systemd-user-activation.nix: Extract module
roberth Dec 8, 2021
a7a1438
nixos/top-level.nix: Make independent of boot modules
roberth Dec 8, 2021
7c0c2e2
nixos: Add system.activation.externalActivationScript
roberth Dec 8, 2021
413be2c
nixos/top-level.nix: Declare dependencies
roberth Dec 8, 2021
b692a92
nixos/users-groups.nix: Declare dependencies
roberth Dec 8, 2021
cc74885
nixos/activation-script: Declare dependencies
roberth Dec 8, 2021
226d20e
lib.nixos: Add users module
roberth Dec 8, 2021
77e8c73
dockerTools.streamLayeredImage: Make robust against cd in fakeRootCom…
roberth Dec 8, 2021
bc6808e
nixos/nixos-core.nix: Add etcActivation module
roberth Dec 8, 2021
eb3fc9a
dockerTools: Update etc example
roberth Dec 8, 2021
6adab4c
nixos/top-level.nix: Add system.checks
roberth Dec 9, 2021
25093d7
nixos/binsh.nix: Extract module
roberth Dec 9, 2021
2f3e9f4
nixos/environment-variables.nix: Extract module
roberth Dec 9, 2021
d9e94ba
nixos/postgresql.nix: Split module, create container, test it
roberth Dec 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ let
options = callLibs ./options.nix;
types = callLibs ./types.nix;

# NixOS
nixos = callLibs ../nixos/nixos-core.nix;

# constants
licenses = callLibs ./licenses.nix;
systems = callLibs ./systems;
Expand Down
40 changes: 40 additions & 0 deletions nixos/modules/config/binsh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ config, lib, utils, pkgs, ... }:

with lib;

let

cfg = config.environment;
in
{
options = {
environment.binsh = mkOption {
default = "${config.system.build.binsh}/bin/sh";
defaultText = literalExpression ''"''${config.system.build.binsh}/bin/sh"'';
example = literalExpression ''"''${pkgs.dash}/bin/dash"'';
type = types.path;
visible = false;
description = ''
The shell executable that is linked system-wide to
<literal>/bin/sh</literal>. Please note that NixOS assumes all
over the place that shell to be Bash, so override the default
setting only if you know exactly what you're doing.
'';
};
};


config = {
system.build.binsh = pkgs.bashInteractive;

system.activationScripts.binsh = stringAfter [ "stdio" ]
''
# Create the required /bin/sh symlink; otherwise lots of things
# (notably the system() function) won't work.
mkdir -m 0755 -p /bin
ln -sfn "${cfg.binsh}" /bin/.sh.tmp
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
'';

};
}
27 changes: 27 additions & 0 deletions nixos/modules/config/environment-variables.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ config, lib, ... }:
let
inherit (lib)
mkOption
types
isList
mapAttrs
concatStringsSep
;
in
{
options = {
environment.variables = mkOption {
default = { };
example = { EDITOR = "nvim"; VISUAL = "nvim"; };
description = ''
A set of environment variables used in the global environment.
These variables will be set on shell initialisation (e.g. in /etc/profile).
The value of each variable can be either a string or a list of
strings. The latter is concatenated, interspersed with colon
characters.
'';
type = with types; attrsOf (either str (listOf str));
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
};
};
}
41 changes: 2 additions & 39 deletions nixos/modules/config/shells-environment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,9 @@ in

{

options = {
imports = [ ./environment-variables.nix ];

environment.variables = mkOption {
default = {};
example = { EDITOR = "nvim"; VISUAL = "nvim"; };
description = ''
A set of environment variables used in the global environment.
These variables will be set on shell initialisation (e.g. in /etc/profile).
The value of each variable can be either a string or a list of
strings. The latter is concatenated, interspersed with colon
characters.
'';
type = with types; attrsOf (either str (listOf str));
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
};
options = {

environment.profiles = mkOption {
default = [];
Expand Down Expand Up @@ -134,20 +122,6 @@ in
type = types.bool;
};

environment.binsh = mkOption {
default = "${config.system.build.binsh}/bin/sh";
defaultText = literalExpression ''"''${config.system.build.binsh}/bin/sh"'';
example = literalExpression ''"''${pkgs.dash}/bin/dash"'';
type = types.path;
visible = false;
description = ''
The shell executable that is linked system-wide to
<literal>/bin/sh</literal>. Please note that NixOS assumes all
over the place that shell to be Bash, so override the default
setting only if you know exactly what you're doing.
'';
};

environment.shells = mkOption {
default = [];
example = literalExpression "[ pkgs.bashInteractive pkgs.zsh ]";
Expand All @@ -163,8 +137,6 @@ in

config = {

system.build.binsh = pkgs.bashInteractive;

# Set session variables in the shell as well. This is usually
# unnecessary, but it allows changes to session variables to take
# effect without restarting the session (e.g. by opening a new
Expand Down Expand Up @@ -210,15 +182,6 @@ in
''}
'';

system.activationScripts.binsh = stringAfter [ "stdio" ]
''
# Create the required /bin/sh symlink; otherwise lots of things
# (notably the system() function) won't work.
mkdir -m 0755 -p /bin
ln -sfn "${cfg.binsh}" /bin/.sh.tmp
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
'';

};

}
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
'';

};
}
1 change: 1 addition & 0 deletions nixos/modules/config/update-users-groups.pl
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ sub parseUser {
my $uid = getpwnam "root";
my $gid = getgrnam "shadow";
my $path = "/etc/shadow";
$gid = 0 unless defined $gid;
(chown($uid, $gid, $path) || die "Failed to change ownership of $path: $!") unless $is_dry;
}

Expand Down
25 changes: 25 additions & 0 deletions nixos/modules/config/user-profiles.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ config, lib, pkgs, ... }:
let
inherit (lib)
mapAttrs'
filterAttrs
;
in
{
config = {
environment.etc = mapAttrs' (_: { packages, name, ... }: {
name = "profiles/per-user/${name}";
value.source = pkgs.buildEnv {
name = "user-environment";
paths = packages;
inherit (config.environment) pathsToLink extraOutputsToInstall;
inherit (config.system.path) ignoreCollisions postBuild;
};
}) (filterAttrs (_: u: u.packages != []) config.users.users);

environment.profiles = [
"$HOME/.nix-profile"
"/etc/profiles/per-user/$USER"
];
};
}
Loading