at 23.05-pre 6.0 kB view raw
1{ config, lib, options, pkgs, ... }: 2 3let 4 cfg = config.system.nixos; 5 opt = options.system.nixos; 6 7 inherit (lib) 8 concatStringsSep mapAttrsToList toLower 9 literalExpression mkRenamedOptionModule mkDefault mkOption trivial types; 10 11 needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s; 12 escapeIfNeccessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"''; 13 attrsToText = attrs: 14 concatStringsSep "\n" ( 15 mapAttrsToList (n: v: ''${n}=${escapeIfNeccessary (toString v)}'') attrs 16 ) + "\n"; 17 18 osReleaseContents = { 19 NAME = "NixOS"; 20 ID = "nixos"; 21 VERSION = "${cfg.release} (${cfg.codeName})"; 22 VERSION_CODENAME = toLower cfg.codeName; 23 VERSION_ID = cfg.release; 24 BUILD_ID = cfg.version; 25 PRETTY_NAME = "NixOS ${cfg.release} (${cfg.codeName})"; 26 LOGO = "nix-snowflake"; 27 HOME_URL = "https://nixos.org/"; 28 DOCUMENTATION_URL = "https://nixos.org/learn.html"; 29 SUPPORT_URL = "https://nixos.org/community.html"; 30 BUG_REPORT_URL = "https://github.com/NixOS/nixpkgs/issues"; 31 }; 32 33 initrdReleaseContents = osReleaseContents // { 34 PRETTY_NAME = "${osReleaseContents.PRETTY_NAME} (Initrd)"; 35 }; 36 initrdRelease = pkgs.writeText "initrd-release" (attrsToText initrdReleaseContents); 37 38in 39{ 40 imports = [ 41 ./label.nix 42 (mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ]) 43 (mkRenamedOptionModule [ "system" "nixosVersionSuffix" ] [ "system" "nixos" "versionSuffix" ]) 44 (mkRenamedOptionModule [ "system" "nixosRevision" ] [ "system" "nixos" "revision" ]) 45 (mkRenamedOptionModule [ "system" "nixosLabel" ] [ "system" "nixos" "label" ]) 46 ]; 47 48 options.boot.initrd.osRelease = mkOption { 49 internal = true; 50 readOnly = true; 51 default = initrdRelease; 52 }; 53 54 options.system = { 55 56 nixos.version = mkOption { 57 internal = true; 58 type = types.str; 59 description = lib.mdDoc "The full NixOS version (e.g. `16.03.1160.f2d4ee1`)."; 60 }; 61 62 nixos.release = mkOption { 63 readOnly = true; 64 type = types.str; 65 default = trivial.release; 66 description = lib.mdDoc "The NixOS release (e.g. `16.03`)."; 67 }; 68 69 nixos.versionSuffix = mkOption { 70 internal = true; 71 type = types.str; 72 default = trivial.versionSuffix; 73 description = lib.mdDoc "The NixOS version suffix (e.g. `1160.f2d4ee1`)."; 74 }; 75 76 nixos.revision = mkOption { 77 internal = true; 78 type = types.nullOr types.str; 79 default = trivial.revisionWithDefault null; 80 description = lib.mdDoc "The Git revision from which this NixOS configuration was built."; 81 }; 82 83 nixos.codeName = mkOption { 84 readOnly = true; 85 type = types.str; 86 default = trivial.codeName; 87 description = lib.mdDoc "The NixOS release code name (e.g. `Emu`)."; 88 }; 89 90 stateVersion = mkOption { 91 type = types.str; 92 default = cfg.release; 93 defaultText = literalExpression "config.${opt.release}"; 94 description = lib.mdDoc '' 95 Every once in a while, a new NixOS release may change 96 configuration defaults in a way incompatible with stateful 97 data. For instance, if the default version of PostgreSQL 98 changes, the new version will probably be unable to read your 99 existing databases. To prevent such breakage, you should set the 100 value of this option to the NixOS release with which you want 101 to be compatible. The effect is that NixOS will use 102 defaults corresponding to the specified release (such as using 103 an older version of PostgreSQL). 104 Its perfectly fine and recommended to leave this value at the 105 release version of the first install of this system. 106 Changing this option will not upgrade your system. In fact it 107 is meant to stay constant exactly when you upgrade your system. 108 You should only bump this option, if you are sure that you can 109 or have migrated all state on your system which is affected 110 by this option. 111 ''; 112 }; 113 114 defaultChannel = mkOption { 115 internal = true; 116 type = types.str; 117 default = "https://nixos.org/channels/nixos-unstable"; 118 description = lib.mdDoc "Default NixOS channel to which the root user is subscribed."; 119 }; 120 121 configurationRevision = mkOption { 122 type = types.nullOr types.str; 123 default = null; 124 description = lib.mdDoc "The Git revision of the top-level flake from which this configuration was built."; 125 }; 126 127 }; 128 129 config = { 130 131 system.nixos = { 132 # These defaults are set here rather than up there so that 133 # changing them would not rebuild the manual 134 version = mkDefault (cfg.release + cfg.versionSuffix); 135 }; 136 137 # Generate /etc/os-release. See 138 # https://www.freedesktop.org/software/systemd/man/os-release.html for the 139 # format. 140 environment.etc = { 141 "lsb-release".text = attrsToText { 142 LSB_VERSION = "${cfg.release} (${cfg.codeName})"; 143 DISTRIB_ID = "nixos"; 144 DISTRIB_RELEASE = cfg.release; 145 DISTRIB_CODENAME = toLower cfg.codeName; 146 DISTRIB_DESCRIPTION = "NixOS ${cfg.release} (${cfg.codeName})"; 147 }; 148 149 "os-release".text = attrsToText osReleaseContents; 150 }; 151 152 # We have to use `warnings` because when warning in the default of the option 153 # the warning would also be shown when building the manual since the manual 154 # has to evaluate the default. 155 # 156 # TODO Remove this and drop the default of the option so people are forced to set it. 157 # Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix 158 warnings = lib.optional (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority) 159 "system.stateVersion is not set, defaulting to ${config.system.stateVersion}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion."; 160 }; 161 162 # uses version info nixpkgs, which requires a full nixpkgs path 163 meta.buildDocsInSandbox = false; 164}