1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.system;
7
8 releaseFile = "${toString pkgs.path}/.version";
9 suffixFile = "${toString pkgs.path}/.version-suffix";
10 revisionFile = "${toString pkgs.path}/.git-revision";
11in
12
13{
14
15 options.system = {
16
17 stateVersion = mkOption {
18 type = types.str;
19 default = cfg.nixosRelease;
20 description = ''
21 Every once in a while, a new NixOS release may change
22 configuration defaults in a way incompatible with stateful
23 data. For instance, if the default version of PostgreSQL
24 changes, the new version will probably be unable to read your
25 existing databases. To prevent such breakage, you can set the
26 value of this option to the NixOS release with which you want
27 to be compatible. The effect is that NixOS will option
28 defaults corresponding to the specified release (such as using
29 an older version of PostgreSQL).
30 '';
31 };
32
33 nixosLabel = mkOption {
34 type = types.str;
35 description = ''
36 NixOS version name to be used in the names of generated
37 outputs and boot labels.
38
39 If you ever wanted to influence the labels in your GRUB menu,
40 this is option is for you.
41
42 Can be set directly or with <envar>NIXOS_LABEL</envar>
43 environment variable for <command>nixos-rebuild</command>,
44 e.g.:
45
46 <screen>
47 #!/bin/sh
48 today=`date +%Y%m%d`
49 branch=`(cd nixpkgs ; git branch 2>/dev/null | sed -n '/^\* / { s|^\* ||; p; }')`
50 revision=`(cd nixpkgs ; git rev-parse HEAD)`
51 export NIXOS_LABEL="$today.$branch-''${revision:0:7}"
52 nixos-rebuild switch</screen>
53 '';
54 };
55
56 nixosVersion = mkOption {
57 internal = true;
58 type = types.str;
59 description = "NixOS version.";
60 };
61
62 nixosRelease = mkOption {
63 readOnly = true;
64 type = types.str;
65 default = readFile releaseFile;
66 description = "NixOS release.";
67 };
68
69 nixosVersionSuffix = mkOption {
70 internal = true;
71 type = types.str;
72 default = if pathExists suffixFile then readFile suffixFile else "pre-git";
73 description = "NixOS version suffix.";
74 };
75
76 nixosRevision = mkOption {
77 internal = true;
78 type = types.str;
79 default = if pathExists revisionFile then readFile revisionFile else "master";
80 description = "NixOS Git revision hash.";
81 };
82
83 nixosCodeName = mkOption {
84 readOnly = true;
85 type = types.str;
86 description = "NixOS release code name.";
87 };
88
89 defaultChannel = mkOption {
90 internal = true;
91 type = types.str;
92 default = https://nixos.org/channels/nixos-unstable;
93 description = "Default NixOS channel to which the root user is subscribed.";
94 };
95
96 };
97
98 config = {
99
100 system = {
101 # These defaults are set here rather than up there so that
102 # changing them would not rebuild the manual
103 nixosLabel = mkDefault (maybeEnv "NIXOS_LABEL" cfg.nixosVersion);
104 nixosVersion = mkDefault (maybeEnv "NIXOS_VERSION" (cfg.nixosRelease + cfg.nixosVersionSuffix));
105
106 # Note: code names must only increase in alphabetical order.
107 nixosCodeName = "Emu";
108 };
109
110 # Generate /etc/os-release. See
111 # http://0pointer.de/public/systemd-man/os-release.html for the
112 # format.
113 environment.etc."os-release".text =
114 ''
115 NAME=NixOS
116 ID=nixos
117 VERSION="${config.system.nixosVersion} (${config.system.nixosCodeName})"
118 VERSION_ID="${config.system.nixosVersion}"
119 PRETTY_NAME="NixOS ${config.system.nixosVersion} (${config.system.nixosCodeName})"
120 HOME_URL="http://nixos.org/"
121 '';
122
123 };
124
125}