summaryrefslogtreecommitdiff
path: root/modules/services/activate-system/default.nix
blob: b3f446e14314672c805dbae659706d98930bf0af (plain)
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
33
34
35
36
37
38
39
40
{ config, lib, pkgs, ... }:

with lib;

let
  inherit (pkgs) stdenv;

  cfg = config.services.activate-system;
in

{
  options = {
    services.activate-system.enable = mkOption {
      type = types.bool;
      default = true;
      description = "Whether to activate system at boot time.";
    };
  };

  config = mkIf cfg.enable {

    launchd.daemons.activate-system = {
      script = ''
        # Make this configuration the current configuration.
        # The readlink is there to ensure that when $systemConfig = /system
        # (which is a symlink to the store), /run/current-system is still
        # used as a garbage collection root.
        ln -sfn $(cat ${config.system.profile}/systemConfig) /run/current-system

        # Prevent the current configuration from being garbage-collected.
        ln -sfn /run/current-system /nix/var/nix/gcroots/current-system

        ${config.system.activationScripts.nix.text}
      '';
      serviceConfig.RunAtLoad = true;
      serviceConfig.KeepAlive.SuccessfulExit = false;
    };

  };
}