1{ config, lib, pkgs, ... }:
2
3with lib;
4
5{
6
7 options = {
8
9 system.stateVersion = mkOption {
10 type = types.str;
11 default = config.system.nixosRelease;
12 description = ''
13 Every once in a while, a new NixOS release may change
14 configuration defaults in a way incompatible with stateful
15 data. For instance, if the default version of PostgreSQL
16 changes, the new version will probably be unable to read your
17 existing databases. To prevent such breakage, you can set the
18 value of this option to the NixOS release with which you want
19 to be compatible. The effect is that NixOS will option
20 defaults corresponding to the specified release (such as using
21 an older version of PostgreSQL).
22 '';
23 };
24
25 system.nixosVersion = mkOption {
26 internal = true;
27 type = types.str;
28 description = "NixOS version.";
29 };
30
31 system.nixosRelease = mkOption {
32 readOnly = true;
33 type = types.str;
34 default = readFile "${toString pkgs.path}/.version";
35 description = "NixOS release.";
36 };
37
38 system.nixosVersionSuffix = mkOption {
39 internal = true;
40 type = types.str;
41 description = "NixOS version suffix.";
42 };
43
44 system.nixosRevision = mkOption {
45 internal = true;
46 type = types.str;
47 description = "NixOS Git revision hash.";
48 };
49
50 system.nixosCodeName = mkOption {
51 readOnly = true;
52 type = types.str;
53 description = "NixOS release code name.";
54 };
55
56 system.defaultChannel = mkOption {
57 internal = true;
58 type = types.str;
59 default = https://nixos.org/channels/nixos-unstable;
60 description = "Default NixOS channel to which the root user is subscribed.";
61 };
62
63 };
64
65 config = {
66
67 system.nixosVersion = mkDefault (config.system.nixosRelease + config.system.nixosVersionSuffix);
68
69 system.nixosVersionSuffix =
70 let suffixFile = "${toString pkgs.path}/.version-suffix"; in
71 mkDefault (if pathExists suffixFile then readFile suffixFile else "pre-git");
72
73 system.nixosRevision =
74 let fn = "${toString pkgs.path}/.git-revision"; in
75 mkDefault (if pathExists fn then readFile fn else "master");
76
77 # Note: code names must only increase in alphabetical order.
78 system.nixosCodeName = "Dingo";
79
80 # Generate /etc/os-release. See
81 # http://0pointer.de/public/systemd-man/os-release.html for the
82 # format.
83 environment.etc."os-release".text =
84 ''
85 NAME=NixOS
86 ID=nixos
87 VERSION="${config.system.nixosVersion} (${config.system.nixosCodeName})"
88 VERSION_ID="${config.system.nixosVersion}"
89 PRETTY_NAME="NixOS ${config.system.nixosVersion} (${config.system.nixosCodeName})"
90 HOME_URL="http://nixos.org/"
91 '';
92
93 };
94
95}