summary refs log tree commit diff
path: root/nixos/modules/misc/version.nix
blob: 5afdcf214f27e6b0d97265fec696f8e9c7f838d3 (plain) (blame)
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
{ config, lib, pkgs, ... }:

with lib;

{

  options = {

    system.nixosVersion = mkOption {
      internal = true;
      type = types.str;
      description = "NixOS version.";
    };

    system.nixosVersionSuffix = mkOption {
      internal = true;
      type = types.str;
      description = "NixOS version suffix.";
    };

    system.nixosRevision = mkOption {
      internal = true;
      type = types.str;
      description = "NixOS Git revision hash.";
    };

    system.nixosCodeName = mkOption {
      internal = true;
      type = types.str;
      description = "NixOS release code name.";
    };

    system.defaultChannel = mkOption {
      internal = true;
      type = types.str;
      default = https://nixos.org/channels/nixos-unstable;
      description = "Default NixOS channel to which the root user is subscribed.";
    };

  };

  config = {

    system.nixosVersion =
      mkDefault (readFile "${toString pkgs.path}/.version" + config.system.nixosVersionSuffix);

    system.nixosVersionSuffix =
      let suffixFile = "${toString pkgs.path}/.version-suffix"; in
      mkDefault (if pathExists suffixFile then readFile suffixFile else "pre-git");

    system.nixosRevision =
      let fn = "${toString pkgs.path}/.git-revision"; in
      mkDefault (if pathExists fn then readFile fn else "master");

    # Note: code names must only increase in alphabetical order.
    system.nixosCodeName = "Dingo";

    # Generate /etc/os-release.  See
    # http://0pointer.de/public/systemd-man/os-release.html for the
    # format.
    environment.etc."os-release".text =
      ''
        NAME=NixOS
        ID=nixos
        VERSION="${config.system.nixosVersion} (${config.system.nixosCodeName})"
        VERSION_ID="${config.system.nixosVersion}"
        PRETTY_NAME="NixOS ${config.system.nixosVersion} (${config.system.nixosCodeName})"
        HOME_URL="http://nixos.org/"
      '';

  };

}