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";
11 gitRepo = "${toString pkgs.path}/.git";
12 gitCommitId = lib.substring 0 7 (commitIdFromGitRepo gitRepo);
13in
14
15{
16
17 options.system = {
18
19 stateVersion = mkOption {
20 type = types.str;
21 default = cfg.nixosRelease;
22 description = ''
23 Every once in a while, a new NixOS release may change
24 configuration defaults in a way incompatible with stateful
25 data. For instance, if the default version of PostgreSQL
26 changes, the new version will probably be unable to read your
27 existing databases. To prevent such breakage, you can set the
28 value of this option to the NixOS release with which you want
29 to be compatible. The effect is that NixOS will option
30 defaults corresponding to the specified release (such as using
31 an older version of PostgreSQL).
32 '';
33 };
34
35 nixosLabel = mkOption {
36 type = types.str;
37 description = ''
38 Label to be used in the names of generated outputs and boot
39 labels.
40 '';
41 };
42
43 nixosVersion = mkOption {
44 internal = true;
45 type = types.str;
46 description = "The full NixOS version (e.g. <literal>16.03.1160.f2d4ee1</literal>).";
47 };
48
49 nixosRelease = mkOption {
50 readOnly = true;
51 type = types.str;
52 default = fileContents releaseFile;
53 description = "The NixOS release (e.g. <literal>16.03</literal>).";
54 };
55
56 nixosVersionSuffix = mkOption {
57 internal = true;
58 type = types.str;
59 default = if pathExists suffixFile then fileContents suffixFile else "pre-git";
60 description = "The NixOS version suffix (e.g. <literal>1160.f2d4ee1</literal>).";
61 };
62
63 nixosRevision = mkOption {
64 internal = true;
65 type = types.str;
66 default = if pathIsDirectory gitRepo then commitIdFromGitRepo gitRepo
67 else if pathExists revisionFile then fileContents revisionFile
68 else "master";
69 description = "The Git revision from which this NixOS configuration was built.";
70 };
71
72 nixosCodeName = mkOption {
73 readOnly = true;
74 type = types.str;
75 description = "The NixOS release code name (e.g. <literal>Emu</literal>).";
76 };
77
78 defaultChannel = mkOption {
79 internal = true;
80 type = types.str;
81 default = https://nixos.org/channels/nixos-unstable;
82 description = "Default NixOS channel to which the root user is subscribed.";
83 };
84
85 };
86
87 config = {
88
89 system = {
90 # These defaults are set here rather than up there so that
91 # changing them would not rebuild the manual
92 nixosLabel = mkDefault cfg.nixosVersion;
93 nixosVersion = mkDefault (cfg.nixosRelease + cfg.nixosVersionSuffix);
94 nixosRevision = mkIf (pathIsDirectory gitRepo) (mkDefault gitCommitId);
95 nixosVersionSuffix = mkIf (pathIsDirectory gitRepo) (mkDefault (".git." + gitCommitId));
96
97 # Note: code names must only increase in alphabetical order.
98 nixosCodeName = "Flounder";
99 };
100
101 # Generate /etc/os-release. See
102 # http://0pointer.de/public/systemd-man/os-release.html for the
103 # format.
104 environment.etc."os-release".text =
105 ''
106 NAME=NixOS
107 ID=nixos
108 VERSION="${config.system.nixosVersion} (${config.system.nixosCodeName})"
109 VERSION_ID="${config.system.nixosVersion}"
110 PRETTY_NAME="NixOS ${config.system.nixosVersion} (${config.system.nixosCodeName})"
111 HOME_URL="http://nixos.org/"
112 '';
113
114 };
115
116}