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