lol

Merge pull request #206655 from vlinkz/distroname

nixos/version: add system.nixos.distroName and system.nixos.distroId options

authored by

Ryan Lahfa and committed by
GitHub
b42ea74b df1262ba

+64 -40
+8 -8
nixos/modules/installer/cd-dvd/iso-image.nix
··· 52 52 buildMenuAdditionalParamsGrub2 = additional: 53 53 let 54 54 finalCfg = { 55 - name = "NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel}"; 55 + name = "${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel}"; 56 56 params = "init=${config.system.build.toplevel}/init ${additional} ${toString config.boot.kernelParams}"; 57 57 image = "/boot/${config.system.boot.loader.kernelFile}"; 58 58 initrd = "/boot/initrd"; ··· 109 109 DEFAULT boot 110 110 111 111 LABEL boot 112 - MENU LABEL NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} 112 + MENU LABEL ${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} 113 113 LINUX /boot/${config.system.boot.loader.kernelFile} 114 114 APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} 115 115 INITRD /boot/${config.system.boot.loader.initrdFile} 116 116 117 117 # A variant to boot with 'nomodeset' 118 118 LABEL boot-nomodeset 119 - MENU LABEL NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (nomodeset) 119 + MENU LABEL ${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (nomodeset) 120 120 LINUX /boot/${config.system.boot.loader.kernelFile} 121 121 APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} nomodeset 122 122 INITRD /boot/${config.system.boot.loader.initrdFile} 123 123 124 124 # A variant to boot with 'copytoram' 125 125 LABEL boot-copytoram 126 - MENU LABEL NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (copytoram) 126 + MENU LABEL ${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (copytoram) 127 127 LINUX /boot/${config.system.boot.loader.kernelFile} 128 128 APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} copytoram 129 129 INITRD /boot/${config.system.boot.loader.initrdFile} 130 130 131 131 # A variant to boot with verbose logging to the console 132 132 LABEL boot-debug 133 - MENU LABEL NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (debug) 133 + MENU LABEL ${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (debug) 134 134 LINUX /boot/${config.system.boot.loader.kernelFile} 135 135 APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} loglevel=7 136 136 INITRD /boot/${config.system.boot.loader.initrdFile} 137 137 138 138 # A variant to boot with a serial console enabled 139 139 LABEL boot-serial 140 - MENU LABEL NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (serial console=ttyS0,115200n8) 140 + MENU LABEL ${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (serial console=ttyS0,115200n8) 141 141 LINUX /boot/${config.system.boot.loader.kernelFile} 142 142 APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} console=ttyS0,115200n8 143 143 INITRD /boot/${config.system.boot.loader.initrdFile} ··· 458 458 }; 459 459 460 460 isoImage.isoBaseName = mkOption { 461 - default = "nixos"; 461 + default = config.system.nixos.distroId; 462 462 description = lib.mdDoc '' 463 463 Prefix of the name of the generated ISO image file. 464 464 ''; ··· 579 579 580 580 isoImage.syslinuxTheme = mkOption { 581 581 default = '' 582 - MENU TITLE NixOS 582 + MENU TITLE ${config.system.nixos.distroName} 583 583 MENU RESOLUTION 800 600 584 584 MENU CLEAR 585 585 MENU ROWS 6
+23 -9
nixos/modules/misc/version.nix
··· 16 16 ) + "\n"; 17 17 18 18 osReleaseContents = { 19 - NAME = "NixOS"; 20 - ID = "nixos"; 19 + NAME = "${cfg.distroName}"; 20 + ID = "${cfg.distroId}"; 21 21 VERSION = "${cfg.release} (${cfg.codeName})"; 22 22 VERSION_CODENAME = toLower cfg.codeName; 23 23 VERSION_ID = cfg.release; 24 24 BUILD_ID = cfg.version; 25 - PRETTY_NAME = "NixOS ${cfg.release} (${cfg.codeName})"; 25 + PRETTY_NAME = "${cfg.distroName} ${cfg.release} (${cfg.codeName})"; 26 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"; 27 + HOME_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/"; 28 + DOCUMENTATION_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/learn.html"; 29 + SUPPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://nixos.org/community.html"; 30 + BUG_REPORT_URL = lib.optionalString (cfg.distroId == "nixos") "https://github.com/NixOS/nixpkgs/issues"; 31 31 } // lib.optionalAttrs (cfg.variant_id != null) { 32 32 VARIANT_ID = cfg.variant_id; 33 33 }; ··· 89 89 description = lib.mdDoc "The NixOS release code name (e.g. `Emu`)."; 90 90 }; 91 91 92 + nixos.distroId = mkOption { 93 + internal = true; 94 + type = types.str; 95 + default = "nixos"; 96 + description = lib.mdDoc "The id of the operating system"; 97 + }; 98 + 99 + nixos.distroName = mkOption { 100 + internal = true; 101 + type = types.str; 102 + default = "NixOS"; 103 + description = lib.mdDoc "The name of the operating system"; 104 + }; 105 + 92 106 nixos.variant_id = mkOption { 93 107 type = types.nullOr (types.strMatching "^[a-z0-9._-]+$"); 94 108 default = null; ··· 155 169 environment.etc = { 156 170 "lsb-release".text = attrsToText { 157 171 LSB_VERSION = "${cfg.release} (${cfg.codeName})"; 158 - DISTRIB_ID = "nixos"; 172 + DISTRIB_ID = "${cfg.distroId}"; 159 173 DISTRIB_RELEASE = cfg.release; 160 174 DISTRIB_CODENAME = toLower cfg.codeName; 161 - DISTRIB_DESCRIPTION = "NixOS ${cfg.release} (${cfg.codeName})"; 175 + DISTRIB_DESCRIPTION = "${cfg.distroName} ${cfg.release} (${cfg.codeName})"; 162 176 }; 163 177 164 178 "os-release".text = attrsToText osReleaseContents;
+2 -1
nixos/modules/services/networking/hostapd.nix
··· 94 94 }; 95 95 96 96 ssid = mkOption { 97 - default = "nixos"; 97 + default = config.system.nixos.distroId; 98 + defaultText = literalExpression "config.system.nixos.distroId"; 98 99 example = "mySpecialSSID"; 99 100 type = types.str; 100 101 description = lib.mdDoc "SSID to be used in IEEE 802.11 management frames.";
+1 -1
nixos/modules/system/activation/bootspec.nix
··· 22 22 system = config.boot.kernelPackages.stdenv.hostPlatform.system; 23 23 kernel = "${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}"; 24 24 kernelParams = config.boot.kernelParams; 25 - label = "NixOS ${config.system.nixos.codeName} ${config.system.nixos.label} (Linux ${config.boot.kernelPackages.kernel.modDirVersion})"; 25 + label = "${config.system.nixos.distroName} ${config.system.nixos.codeName} ${config.system.nixos.label} (Linux ${config.boot.kernelPackages.kernel.modDirVersion})"; 26 26 27 27 inherit (cfg) extensions; 28 28 } // lib.optionalAttrs config.boot.initrd.enable {
+1 -1
nixos/modules/system/activation/switch-to-configuration.pl
··· 84 84 85 85 # This is a NixOS installation if it has /etc/NIXOS or a proper 86 86 # /etc/os-release. 87 - if (!-f "/etc/NIXOS" && (read_file("/etc/os-release", err_mode => "quiet") // "") !~ /^ID="?nixos"?/msx) { 87 + if (!-f "/etc/NIXOS" && (read_file("/etc/os-release", err_mode => "quiet") // "") !~ /^ID="?@distroId@"?/msx) { 88 88 die("This is not a NixOS installation!\n"); 89 89 } 90 90
+1
nixos/modules/system/activation/top-level.nix
··· 65 65 66 66 mkdir $out/bin 67 67 export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" 68 + export distroId=${config.system.nixos.distroId}; 68 69 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration 69 70 chmod +x $out/bin/switch-to-configuration 70 71 ${optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
+2 -1
nixos/modules/system/boot/loader/grub/grub.nix
··· 55 55 grubTargetEfi = if cfg.efiSupport && (cfg.version == 2) then f (grubEfi.grubTarget or "") else ""; 56 56 bootPath = args.path; 57 57 storePath = config.boot.loader.grub.storePath; 58 - bootloaderId = if args.efiBootloaderId == null then "NixOS${efiSysMountPoint'}" else args.efiBootloaderId; 58 + bootloaderId = if args.efiBootloaderId == null then "${config.system.nixos.distroName}${efiSysMountPoint'}" else args.efiBootloaderId; 59 59 timeout = if config.boot.loader.timeout == null then -1 else config.boot.loader.timeout; 60 60 users = if cfg.users == {} || cfg.version != 1 then cfg.users else throw "GRUB version 1 does not support user accounts."; 61 61 theme = f cfg.theme; ··· 759 759 src = ./install-grub.pl; 760 760 utillinux = pkgs.util-linux; 761 761 btrfsprogs = pkgs.btrfs-progs; 762 + inherit (config.system.nixos) distroName; 762 763 }; 763 764 perl = pkgs.perl.withPackages (p: with p; [ 764 765 FileSlurp FileCopyRecursive
+5 -5
nixos/modules/system/boot/loader/grub/install-grub.pl
··· 511 511 # Add default entries. 512 512 $conf .= "$extraEntries\n" if $extraEntriesBeforeNixOS; 513 513 514 - addEntry("NixOS - Default", $defaultConfig, $entryOptions); 514 + addEntry("@distroName@ - Default", $defaultConfig, $entryOptions); 515 515 516 516 $conf .= "$extraEntries\n" unless $extraEntriesBeforeNixOS; 517 517 ··· 536 536 my $linkname = basename($link); 537 537 $entryName = "($linkname - $date - $version)"; 538 538 } 539 - addEntry("NixOS - $entryName", $link); 539 + addEntry("@distroName@ - $entryName", $link); 540 540 } 541 541 542 542 my $grubBootPath = $grubBoot->path; ··· 568 568 -e "$link/nixos-version" 569 569 ? readFile("$link/nixos-version") 570 570 : basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]); 571 - addEntry("NixOS - Configuration " . nrFromGen($link) . " ($date - $version)", $link, $subEntryOptions); 571 + addEntry("@distroName@ - Configuration " . nrFromGen($link) . " ($date - $version)", $link, $subEntryOptions); 572 572 } 573 573 574 574 $conf .= "}\n" if $grubVersion == 2; 575 575 } 576 576 577 - addProfile "/nix/var/nix/profiles/system", "NixOS - All configurations"; 577 + addProfile "/nix/var/nix/profiles/system", "@distroName@ - All configurations"; 578 578 579 579 if ($grubVersion == 2) { 580 580 for my $profile (glob "/nix/var/nix/profiles/system-profiles/*") { 581 581 my $name = basename($profile); 582 582 next unless $name =~ /^\w+$/; 583 - addProfile $profile, "NixOS - Profile '$name'"; 583 + addProfile $profile, "@distroName@ - Profile '$name'"; 584 584 } 585 585 } 586 586
+3 -3
nixos/modules/system/boot/loader/init-script/init-script-builder.sh
··· 64 64 65 65 mkdir -p /boot /sbin 66 66 67 - addEntry "NixOS - Default" $defaultConfig "" 67 + addEntry "@distroName@ - Default" $defaultConfig "" 68 68 69 69 # Add all generations of the system profile to the menu, in reverse 70 70 # (most recent to least recent) order. 71 71 for link in $((ls -d $defaultConfig/specialisation/* ) | sort -n); do 72 72 date=$(stat --printf="%y\n" $link | sed 's/\..*//') 73 - addEntry "NixOS - variation" $link "" 73 + addEntry "@distroName@ - variation" $link "" 74 74 done 75 75 76 76 for generation in $( ··· 85 85 else 86 86 suffix="($date)" 87 87 fi 88 - addEntry "NixOS - Configuration $generation $suffix" $link "$generation ($date)" 88 + addEntry "@distroName@ - Configuration $generation $suffix" $link "$generation ($date)" 89 89 done 90 90 91 91 mv $tmpOther $targetOther
+1
nixos/modules/system/boot/loader/init-script/init-script.nix
··· 8 8 src = ./init-script-builder.sh; 9 9 isExecutable = true; 10 10 inherit (pkgs) bash; 11 + inherit (config.nixos.system) distroName; 11 12 path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; 12 13 }; 13 14
+4 -4
nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py
··· 42 42 else: 43 43 return d 44 44 45 - BOOT_ENTRY = """title NixOS{profile}{specialisation} 45 + BOOT_ENTRY = """title @distroName@{profile}{specialisation} 46 46 version Generation {generation} {description} 47 47 linux {kernel} 48 48 initrd {initrd} ··· 99 99 build_time = int(os.path.getctime(generation_dir)) 100 100 build_date = datetime.datetime.fromtimestamp(build_time).strftime('%F') 101 101 102 - description = "NixOS {}, Linux Kernel {}, Built on {}".format( 102 + description = "@distroName@ {}, Linux Kernel {}, Built on {}".format( 103 103 nixos_version, kernel_version, build_date 104 104 ) 105 105 ··· 206 206 return [] 207 207 208 208 def main() -> None: 209 - parser = argparse.ArgumentParser(description='Update NixOS-related systemd-boot files') 210 - parser.add_argument('default_config', metavar='DEFAULT-CONFIG', help='The default NixOS config to boot') 209 + parser = argparse.ArgumentParser(description='Update @distroName@-related systemd-boot files') 210 + parser.add_argument('default_config', metavar='DEFAULT-CONFIG', help='The default @distroName@ config to boot') 211 211 args = parser.parse_args() 212 212 213 213 try:
+2
nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
··· 30 30 31 31 inherit (efi) efiSysMountPoint canTouchEfiVariables; 32 32 33 + inherit (config.system.nixos) distroName; 34 + 33 35 memtest86 = if cfg.memtest86.enable then pkgs.memtest86-efi else ""; 34 36 35 37 netbootxyz = if cfg.netbootxyz.enable then pkgs.netbootxyz-efi else "";
+2 -2
nixos/modules/system/boot/stage-1-init.sh
··· 73 73 74 74 # Print a greeting. 75 75 info 76 - info "<<< NixOS Stage 1 >>>" 76 + info "<<< @distroName@ Stage 1 >>>" 77 77 info 78 78 79 79 # Make several required directories. ··· 422 422 local root="$1" 423 423 424 424 echo 425 - echo -e "\e[1;33m<<< NixOS is now lustrating the root filesystem (cruft goes to /old-root) >>>\e[0m" 425 + echo -e "\e[1;33m<<< @distroName@ is now lustrating the root filesystem (cruft goes to /old-root) >>>\e[0m" 426 426 echo 427 427 428 428 mkdir -m 0755 -p "$root/old-root.tmp"
+2
nixos/modules/system/boot/stage-1.nix
··· 342 342 343 343 inherit (config.boot) resumeDevice; 344 344 345 + inherit (config.system.nixos) distroName; 346 + 345 347 inherit (config.system.build) earlyMountScript; 346 348 347 349 inherit (config.boot.initrd) checkJournalingFS verbose
+1 -1
nixos/modules/system/boot/stage-2-init.sh
··· 19 19 20 20 # Print a greeting. 21 21 echo 22 - echo -e "\e[1;32m<<< NixOS Stage 2 >>>\e[0m" 22 + echo -e "\e[1;32m<<< @distroName@ Stage 2 >>>\e[0m" 23 23 echo 24 24 25 25
+1
nixos/modules/system/boot/stage-2.nix
··· 11 11 shellDebug = "${pkgs.bashInteractive}/bin/bash"; 12 12 shell = "${pkgs.bash}/bin/bash"; 13 13 inherit (config.boot) readOnlyNixStore systemdExecutable extraSystemdUnitPaths; 14 + inherit (config.system.nixos) distroName; 14 15 isExecutable = true; 15 16 inherit useHostResolvConf; 16 17 inherit (config.system.build) earlyMountScript;
+2 -1
nixos/modules/tasks/network-interfaces.nix
··· 434 434 options = { 435 435 436 436 networking.hostName = mkOption { 437 - default = "nixos"; 437 + default = config.system.nixos.distroId; 438 + defaultText = literalExpression "config.system.nixos.distroId"; 438 439 # Only allow hostnames without the domain name part (i.e. no FQDNs, see 439 440 # e.g. "man 5 hostname") and require valid DNS labels (recommended 440 441 # syntax). Note: We also allow underscores for compatibility/legacy
+2 -2
nixos/modules/virtualisation/lxc-container.nix
··· 123 123 architecture = builtins.elemAt (builtins.match "^([a-z0-9_]+).+" (toString pkgs.system)) 0; 124 124 creation_date = 1; 125 125 properties = { 126 - description = "NixOS ${config.system.nixos.codeName} ${config.system.nixos.label} ${pkgs.system}"; 127 - os = "nixos"; 126 + description = "${config.system.nixos.distroName} ${config.system.nixos.codeName} ${config.system.nixos.label} ${pkgs.system}"; 127 + os = "${config.system.nixos.distroId}"; 128 128 release = "${config.system.nixos.codeName}"; 129 129 }; 130 130 templates = templates.properties;
+1 -1
nixos/modules/virtualisation/virtualbox-image.nix
··· 41 41 }; 42 42 vmName = mkOption { 43 43 type = types.str; 44 - default = "NixOS ${config.system.nixos.label} (${pkgs.stdenv.hostPlatform.system})"; 44 + default = "${config.system.nixos.distroName} ${config.system.nixos.label} (${pkgs.stdenv.hostPlatform.system})"; 45 45 description = lib.mdDoc '' 46 46 The name of the VirtualBox appliance. 47 47 '';