Commit Graph

52 Commits

Author SHA1 Message Date
Sander van der Burg
5c8ed06fc9 systemd: allow custom unit folders to be configured with SYSTEMD_UNIT_PATH 2021-03-22 20:41:12 +01:00
Graham Christensen
64dd9c1d6a
stage-2: parameterized systemd executable
This lets users do sneaky things before systemd starts, and
permanently affect the environment in which systemd runs. For example,
we could start systemd in a non-default network namespace by setting
the systemdExecutable to a wrapper script containing:

    #!/bin/sh
    ip netns add virtual
    touch /var/run/netns/physical
    mount -o bind /proc/self/ns/net /var/run/netns/physical
    exec ip netns exec virtual systemd

_note: the above example does literally work, but there are unresolved
problems with udev and dhcp._
2020-07-14 13:18:14 -04:00
Eelco Dolstra
2c97f0669d
Typo 2019-10-10 16:24:33 +02:00
Jamey Sharp
8d40083690 nixos/stage-2: create empty machine-id at boot
Previously, the activation script was responsible for ensuring that
/etc/machine-id exists. However, the only time it could not already
exist is during stage-2-init, not while switching configurations,
because one of the first things systemd does when starting up as PID 1
is to create this file. So I've moved the initialization to
stage-2-init.

Furthermore, since systemd will do the equivalent of
systemd-machine-id-setup if /etc/machine-id doesn't have valid contents,
we don't need to do that ourselves.

We _do_, however, want to ensure that the file at least exists, because
systemd also uses the non-existence of this file to guess that this is a
first-boot situation. In that case, systemd tries to create some
symlinks in /etc/systemd/system according to its presets, which it can't
do because we've already populated /etc according to the current NixOS
configuration.

This is not necessary for any other activation script snippets, so it's
okay to do it after stage-2-init runs the activation script. None of
them declare a dependency on the "systemd" snippet. Also, most of them
only create files or directories in ways that obviously don't need the
machine-id set.
2018-09-30 10:45:35 -07:00
Matt McHenry
94a906b59a systemd: ensure fsck Requires/After links are created in mount units
systemd-fsck-generator only produces these lines if it can find the
necessary fsck executable in its PATH.

fixes #29139.
2018-08-28 17:12:49 +02:00
Eelco Dolstra
0236a947d0
mkdir -> install -d
Fixes #38421.
2018-04-04 13:04:35 +02:00
Eelco Dolstra
cc0caac098
Move creation of /root to the activation script
...so it appears in a new installation before rebooting the system.
2018-02-05 22:12:18 +01:00
Jörg Thalheim
62c79a1de8
stage-2: shellsheck recommendations 2017-04-05 21:40:57 +02:00
Jörg Thalheim
e3f031b200
stage-2: reduce mkdir commands 2017-04-05 21:40:51 +02:00
Jörg Thalheim
a17344c2ad
stage-2: process options as first action
this way `set -x` is set early
2017-04-05 09:05:18 +02:00
Jörg Thalheim
b42af25223
stage-2: replace readonly-mountpoint by findmnt 2017-04-05 09:05:18 +02:00
Jörg Thalheim
a5ad8b4f69
stage-2: simplify exporting path 2017-04-05 09:05:13 +02:00
Franz Pletz
e4fb2bb0c5
Revert "nixos/stage2: Check for each special mount individually and mount missing ones. (#21370)"
This reverts commit 712e62c260.

This commit broke NixOS containers. Systemd wouldn't detect if a container
started successfully and would kill it again after a grace period.

Additionally this prints mount errors due to already mounted filesystems
at boot.
2017-01-10 17:35:38 +01:00
Sebastian Hagen
712e62c260 nixos/stage2: Check for each special mount individually and mount missing ones. (#21370) 2017-01-09 10:32:23 +01:00
Nikolay Amiantov
79d4636d50 stage-2 init: move /run/keys mount to boot.specialFileSystems 2016-09-17 15:39:24 +03:00
aszlig
dd98b6fb9f
nixos/stage2: Fix mounting special filesystems
This partially reverts commit ab9537ca22.

From the manpage of systemd-nspawn(1):

  Note that systemd-nspawn will mount file systems private to the
  container to /dev, /run and similar.

Testing this in a shell turns out:

$ sudo systemd-nspawn --bind-ro=/nix/store "$(readlink "$(which ls)")" /proc
Spawning container aszlig on /home/aszlig.
Press ^] three times within 1s to kill container.
/etc/localtime does not point into /usr/share/zoneinfo/, not updating
container timezone.
1          execdomains  kpageflags    stat
acpi       fb           loadavg       swaps
asound     filesystems  locks         sys
buddyinfo  fs           meminfo       sysrq-trigger
bus        interrupts   misc          sysvipc
cgroups    iomem        modules       thread-self
cmdline    ioports      mounts        timer_list
config.gz  irq          mtrr          timer_stats
consoles   kallsyms     net           tty
cpuinfo    kcore        pagetypeinfo  uptime
crypto     key-users    partitions    version
devices    keys         scsi          vmallocinfo
diskstats  kmsg         self          vmstat
dma        kpagecgroup  slabinfo      zoneinfo
driver     kpagecount   softirqs
Container aszlig exited successfully.

So the test on whether PID 1 exists in /proc is enough, because if we
use PID namespaces there actually _is_ a PID 1 (as shown above) and the
special file systems are already mounted. A test on the $containers
variable actually mounts them twice.

This unbreaks NixOS containers and I've tested this against the
containers-imperative NixOS test.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Cc: @rickynils, @shlevy, @edolstra
2016-09-07 18:10:08 +02:00
Rickard Nilsson
ab9537ca22 nixos: Generalise the container tests in stage-2 boot
This way, stage-2 behaves correctly also for libvirt-lxc containers.

Some more discussion on this:
a7a08188bf
bfe46a653b
2016-09-07 07:50:04 +00:00
Domen Kožar
a6670c1a0b Fixes #18124: atomically replace /var/setuid-wrappers/ (#18186)
Before this commit updating /var/setuid-wrappers/ folder introduced
a small window where NixOS activation scripts could be terminated
and resulted into empty /var/setuid-wrappers/ folder.

That's very unfortunate because one might lose sudo binary.

Instead we use two atomic operations mv and ln (as described in
https://axialcorps.com/2013/07/03/atomically-replacing-files-and-directories/)
to achieve atomicity.

Since /var/setuid-wrappers is not a directory anymore, tmpfs mountpoints
were removed in installation scripts and in boot process.

Tested:

- upgrade /var/setuid-wrappers/ from folder to a symlink
- make sure /run/setuid-wrappers-dirs/ legacy symlink is really deleted
2016-09-01 20:57:51 +02:00
Nikolay Amiantov
6efcfe03ae nixos filesystems: unify early filesystems handling
A new internal config option `fileSystems.<name>.early` is added to indicate
that the filesystem needs to be loaded very early (i.e. in initrd). They are
transformed to a shell script in `system.build.earlyMountScript` with calls to
an undefined `specialMount` function, which is expected to be caller-specific.
This option is used by stage-1, stage-2 and activation script to set up and
remount those filesystems.  Options for them are updated according to systemd
defaults.
2016-08-27 13:38:20 +03:00
Nikolay Amiantov
6b41f1132c nixos treewide: don't set MODULE_DIR 2016-08-19 17:56:54 +03:00
Shea Levy
9adad8612b Revert "Merge branch 'modprobe-fix' of git://github.com/abbradar/nixpkgs"
Was meant to go into staging, sorry

This reverts commit 57b2d1e9b0, reversing
changes made to 760b2b9048.
2016-08-15 19:05:52 -04:00
Nikolay Amiantov
1f63958772 nixos treewide: don't set MODULE_DIR 2016-08-16 00:19:25 +03:00
Nahum Shalman
9b0a5ced13 stage2: if no /proc, also mount /sys 2016-06-01 13:26:14 +00:00
Roger Qiu
5cf823e1f4 nixos/stage-1/2: Added -r option to read so that read interprets backslashes literally, and corrected the comment about optional logging. 2016-02-24 18:54:25 +11:00
Eelco Dolstra
deae4eff7b Make stage-1/2 logging unconditional, and drop log level to "debug"
Using "debug" level prevents spamming the console with messages twice
(once directly and once via kmsg).
2016-02-23 11:56:09 +01:00
Roger Qiu
474d5a7bd0 nixos/stage-2: Added boot.logCommands 2016-02-23 11:56:09 +01:00
Eelco Dolstra
ec82157ac5 stage-2: Don't run hwclock in containers
(cherry picked from commit b978df019a)
2015-07-22 12:23:52 +02:00
Eelco Dolstra
9647609e3e stage-1: Don't mount /dev/shm if it's already mounted
(cherry picked from commit c8ef598945)
2015-07-22 12:23:48 +02:00
Eelco Dolstra
a38f130126 Revert "Set stricter permissions on /nix/store"
This reverts commit 066758758e7c0768ff8da51d208cdae0f33b368c because
it breaks NixOS VM tests.
2015-04-07 15:10:41 +02:00
Eelco Dolstra
224d0d5302 Set stricter permissions on /nix/store
The nixbld group doesn't need read permission, it only needs write and
execute permission.

(cherry picked from commit 066758758e7c0768ff8da51d208cdae0f33b368c)
2015-03-18 10:58:08 +01:00
Thomas Strobel
c62e42e9c5 Enhance stage-1/2 scripts for better dealing with squashfs 2015-02-20 17:42:22 +01:00
Eelco Dolstra
efa8fc2b0a Paranoia 2015-01-15 18:37:55 +01:00
William A. Kennington III
1860ee27b0 nixos/networking: Fixes 2014-11-26 16:29:24 -08:00
Eelco Dolstra
a7a08188bf Containers: Don't remount / 2014-08-18 17:14:43 +02:00
Eelco Dolstra
0d3b3bd01b systemd: Use the default log target ("journal-or-kmsg")
This ensures that early systemd messages end up in the journal (via
the kmsg buffer).
2014-08-06 14:15:12 +02:00
Emery Hemingway
63d259df32 nixos: tmp on tmpfs option
/tmp cleaning is done by systemd rather than stage-2-init
enableEmergencyMode moved from systemd to seperate module
new option to mount tmp on tmpfs
new option to enable additional units shipped with systemd
2014-07-30 16:19:26 +02:00
Eelco Dolstra
39a6750362 Shut up a warning in stage 2 2014-07-30 16:07:09 +02:00
Eelco Dolstra
906aa9ccb1 Make pseudo-filesystems show up as "tmpfs" etc. rather than "none" in df 2014-06-05 13:39:17 +02:00
Shea Levy
57ed344917 Fix /run/keys permissions 2014-05-27 17:22:25 -04:00
Eelco Dolstra
9f1c9404da Put /var/setuid-wrappers on a tmpfs
This allows all other filesystems to be mounted without the suid
option.
2014-04-19 12:40:09 +02:00
Eelco Dolstra
2a64b0a91b Shut up warning about resolv.conf missing 2014-04-19 12:34:59 +02:00
Eelco Dolstra
48d90cf3b6 Revert "Put /nix/var/nix/{temproots,userpool} on a tmpfs"
This reverts commit dd49094a25. Nix
barfs if /nix/var/nix/temproots is a symlink :-(
2014-04-18 18:37:07 +02:00
Eelco Dolstra
dd49094a25 Put /nix/var/nix/{temproots,userpool} on a tmpfs 2014-04-18 16:56:20 +02:00
Eelco Dolstra
c13cede19d Remove long-obsolete /nix/var/nix/chroots directory 2014-04-18 16:50:37 +02:00
Eelco Dolstra
21573af9fb Containers: Use /etc/resolv.conf supplied by the host
This used to work with systemd-nspawn 203, because it bind-mounted
/etc/resolv.conf (so openresolv couldn't overwrite it). Now it's just
copied, so we need some special handling.
2014-04-18 16:48:11 +02:00
Eelco Dolstra
bb9304e280 Remove creation of /tmp/.ICE-unix
This is now done by tmpfiles.
2014-04-17 16:14:56 +02:00
Shea Levy
77181be713 Set /run/keys ownership based on numerical ids
See comments on 4ab5646417
2014-03-19 05:18:24 -04:00
Eelco Dolstra
7d8fea797a Run hwclock --hctosys to initialize the system time 2014-03-18 23:14:34 +01:00
Eelco Dolstra
08095f97ce Typo 2014-03-18 22:40:39 +01:00
Shea Levy
4ab5646417 Add a keys group with read access to /run/keys
This allows processes running as unprivileged users access to keys they might need
2014-02-11 07:00:10 -05:00