nixos/os-release: generate from attrset

This commit is contained in:
Peter Hoeg 2022-02-28 14:44:38 +08:00
parent 3143de97f9
commit bae181d3f0

View File

@ -1,12 +1,17 @@
{ config, lib, options, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib;
let let
cfg = config.system.nixos; cfg = config.system.nixos;
opt = options.system.nixos; opt = options.system.nixos;
in
inherit (lib)
concatStringsSep mapAttrsToList toLower
literalExpression mkRenamedOptionModule mkDefault mkOption trivial types;
attrsToText = attrs:
concatStringsSep "\n" (mapAttrsToList (n: v: ''${n}="${toString v}"'') attrs);
in
{ {
imports = [ imports = [
(mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ]) (mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ])
@ -101,22 +106,30 @@ in
# Generate /etc/os-release. See # Generate /etc/os-release. See
# https://www.freedesktop.org/software/systemd/man/os-release.html for the # https://www.freedesktop.org/software/systemd/man/os-release.html for the
# format. # format.
environment.etc.os-release.text = environment.etc = {
'' "lsb-release".text = attrsToText {
NAME=NixOS LSB_VERSION = "${cfg.release} (${cfg.codeName})";
ID=nixos DISTRIB_ID = "nixos";
VERSION="${cfg.release} (${cfg.codeName})" DISTRIB_RELEASE = cfg.release;
VERSION_CODENAME=${toLower cfg.codeName} DISTRIB_CODENAME = toLower cfg.codeName;
VERSION_ID="${cfg.release}" DISTRIB_DESCRIPTION = "NixOS ${cfg.release} (${cfg.codeName})";
BUILD_ID="${cfg.version}" };
PRETTY_NAME="NixOS ${cfg.release} (${cfg.codeName})"
LOGO="nix-snowflake"
HOME_URL="https://nixos.org/"
DOCUMENTATION_URL="https://nixos.org/learn.html"
SUPPORT_URL="https://nixos.org/community.html"
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
'';
"os-release".text = attrsToText {
NAME = "NixOS";
ID = "nixos";
VERSION = "${cfg.release} (${cfg.codeName})";
VERSION_CODENAME = toLower cfg.codeName;
VERSION_ID = cfg.release;
BUILD_ID = cfg.version;
PRETTY_NAME = "NixOS ${cfg.release} (${cfg.codeName})";
LOGO = "nix-snowflake";
HOME_URL = "https://nixos.org/";
DOCUMENTATION_URL = "https://nixos.org/learn.html";
SUPPORT_URL = "https://nixos.org/community.html";
BUG_REPORT_URL = "https://github.com/NixOS/nixpkgs/issues";
};
};
}; };
# uses version info nixpkgs, which requires a full nixpkgs path # uses version info nixpkgs, which requires a full nixpkgs path