Skip to content

Commit bae181d

Browse files
committed
nixos/os-release: generate from attrset
1 parent 3143de9 commit bae181d

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

nixos/modules/misc/version.nix

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
{ config, lib, options, pkgs, ... }:
22

3-
with lib;
4-
53
let
64
cfg = config.system.nixos;
75
opt = options.system.nixos;
8-
in
96

7+
inherit (lib)
8+
concatStringsSep mapAttrsToList toLower
9+
literalExpression mkRenamedOptionModule mkDefault mkOption trivial types;
10+
11+
attrsToText = attrs:
12+
concatStringsSep "\n" (mapAttrsToList (n: v: ''${n}="${toString v}"'') attrs);
13+
14+
in
1015
{
1116
imports = [
1217
(mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ])
@@ -101,22 +106,30 @@ in
101106
# Generate /etc/os-release. See
102107
# https://www.freedesktop.org/software/systemd/man/os-release.html for the
103108
# format.
104-
environment.etc.os-release.text =
105-
''
106-
NAME=NixOS
107-
ID=nixos
108-
VERSION="${cfg.release} (${cfg.codeName})"
109-
VERSION_CODENAME=${toLower cfg.codeName}
110-
VERSION_ID="${cfg.release}"
111-
BUILD_ID="${cfg.version}"
112-
PRETTY_NAME="NixOS ${cfg.release} (${cfg.codeName})"
113-
LOGO="nix-snowflake"
114-
HOME_URL="https://nixos.org/"
115-
DOCUMENTATION_URL="https://nixos.org/learn.html"
116-
SUPPORT_URL="https://nixos.org/community.html"
117-
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
118-
'';
119-
109+
environment.etc = {
110+
"lsb-release".text = attrsToText {
111+
LSB_VERSION = "${cfg.release} (${cfg.codeName})";
112+
DISTRIB_ID = "nixos";
113+
DISTRIB_RELEASE = cfg.release;
114+
DISTRIB_CODENAME = toLower cfg.codeName;
115+
DISTRIB_DESCRIPTION = "NixOS ${cfg.release} (${cfg.codeName})";
116+
};
117+
118+
"os-release".text = attrsToText {
119+
NAME = "NixOS";
120+
ID = "nixos";
121+
VERSION = "${cfg.release} (${cfg.codeName})";
122+
VERSION_CODENAME = toLower cfg.codeName;
123+
VERSION_ID = cfg.release;
124+
BUILD_ID = cfg.version;
125+
PRETTY_NAME = "NixOS ${cfg.release} (${cfg.codeName})";
126+
LOGO = "nix-snowflake";
127+
HOME_URL = "https://nixos.org/";
128+
DOCUMENTATION_URL = "https://nixos.org/learn.html";
129+
SUPPORT_URL = "https://nixos.org/community.html";
130+
BUG_REPORT_URL = "https://github.com/NixOS/nixpkgs/issues";
131+
};
132+
};
120133
};
121134

122135
# uses version info nixpkgs, which requires a full nixpkgs path

0 commit comments

Comments
 (0)