naitokosuke · dotfiles

The Nix daemon itself: Lix, flakes, a weekly GC and store optimisation, and the zsh files nix-darwin writes to /etc.

System zsh files

nix-darwin writes /etc/zsh*, which load the system environment and put every profile's share/zsh on fpath, so packaged completions work (#544). compinit and the prompt are left to home/zsh.nix and home/starship.nix.

lines 16–20
16
17
18
19
20  programs.zsh = {
    enable = true;
    enableGlobalCompInit = false;
    promptInit = "";
  };

Lix

nixd and devenv (./packages.nix) embed an evaluator and link the CppNix libraries. nixpkgs' lixPackageSets has no Lix build of either, so that mix is intentional (#561). nix-direnv has one and uses it (home/direnv.nix).

line 26
26  nix.package = pkgs.lix;

Weekly GC with nh

nh clean all instead of nix.gc: besides system and user generations it also drops stale GC roots (result links, nix-direnv profiles). Keeps the last 14 days as a rollback window. Runs as root, so nh skips self-elevation. home-manager's programs.nh.clean is not used because on Darwin it only runs nh clean user. An hour later, nix.optimise hard-links identical files across whatever the cleanup left.

lines 35–52
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52  launchd.daemons.nh-clean = {
    command = "${lib.getExe pkgs.nh} clean all --keep-since 14d";
    path = [ config.nix.package ];
    serviceConfig.RunAtLoad = false;
    serviceConfig.StartCalendarInterval = {
      Weekday = 0;
      Hour = 3;
      Minute = 15;
    };
  };
  nix.optimise = {
    automatic = true;
    interval = {
      Weekday = 0;
      Hour = 4;
      Minute = 15;
    };
  };

Flakes, and no trusted user

Flakes only: without nix.channel.enable = false NIX_PATH still carries the root channels. The primary user is deliberately not in trusted-users. A trusted user can set any daemon setting, including substituters and post-build-hook, which amounts to root, and every process running as that user inherits it (#560). What needed that trust is declared here instead: the binary cache devenv's nixpkgs is built into.

lines 61–69
61
62
63
64
65
66
67
68
69  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];
  nix.channel.enable = false;
  nix.settings.substituters = [ "https://devenv.cachix.org" ];
  nix.settings.trusted-public-keys = [
    "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
  ];

Build provenance

The flake's git revision, so a running system traces back to the commit it was built from.

lines 74–75
74
75  system.configurationRevision = inputs.self.rev or inputs.self.dirtyRev or null;
  system.stateVersion = 5;
View the complete file77 lines · nix.nix
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77# The Nix daemon itself: Lix, flakes, a weekly GC and store optimisation, and
# the zsh files nix-darwin writes to /etc.
{
  config,
  inputs,
  lib,
  pkgs,
  ...
}:

{
  ## System zsh files
  # nix-darwin writes /etc/zsh*, which load the system environment and put
  # every profile's share/zsh on fpath, so packaged completions work (#544).
  # compinit and the prompt are left to home/zsh.nix and home/starship.nix.
  programs.zsh = {
    enable = true;
    enableGlobalCompInit = false;
    promptInit = "";
  };

  ## Lix
  # nixd and devenv (./packages.nix) embed an evaluator and link the CppNix
  # libraries. nixpkgs' lixPackageSets has no Lix build of either, so that mix
  # is intentional (#561). nix-direnv has one and uses it (home/direnv.nix).
  nix.package = pkgs.lix;

  ## Weekly GC with nh
  # `nh clean all` instead of nix.gc: besides system and user generations it
  # also drops stale GC roots (`result` links, nix-direnv profiles). Keeps the
  # last 14 days as a rollback window. Runs as root, so nh skips
  # self-elevation. home-manager's programs.nh.clean is not used because on
  # Darwin it only runs `nh clean user`. An hour later, `nix.optimise`
  # hard-links identical files across whatever the cleanup left.
  launchd.daemons.nh-clean = {
    command = "${lib.getExe pkgs.nh} clean all --keep-since 14d";
    path = [ config.nix.package ];
    serviceConfig.RunAtLoad = false;
    serviceConfig.StartCalendarInterval = {
      Weekday = 0;
      Hour = 3;
      Minute = 15;
    };
  };
  nix.optimise = {
    automatic = true;
    interval = {
      Weekday = 0;
      Hour = 4;
      Minute = 15;
    };
  };

  ## Flakes, and no trusted user
  # Flakes only: without `nix.channel.enable = false` NIX_PATH still carries
  # the root channels. The primary user is deliberately not in trusted-users.
  # A trusted user can set any daemon setting, including substituters and
  # post-build-hook, which amounts to root, and every process running as that
  # user inherits it (#560). What needed that trust is declared here instead:
  # the binary cache devenv's nixpkgs is built into.
  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];
  nix.channel.enable = false;
  nix.settings.substituters = [ "https://devenv.cachix.org" ];
  nix.settings.trusted-public-keys = [
    "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
  ];

  ## Build provenance
  # The flake's git revision, so a running system traces back to the commit
  # it was built from.
  system.configurationRevision = inputs.self.rev or inputs.self.dirtyRev or null;
  system.stateVersion = 5;
}
77 lines·2,636 chars·NIX