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