summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/os-release.nix
blob: 929ec45d907fe92ddebaeb76384d6a49354087b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{ config, lib, ... }:
with lib;
let
  nixos-version-id = if (hasAttr "nixos" config.system) then
    "${config.system.nixos.version}" else "${config.system.nixosVersion}";
  nixos-codeName = if (hasAttr "nixos" config.system) then
    "${config.system.nixos.codeName}" else "${config.system.nixosCodeName}";
  nixos-version = "${nixos-version-id} (${nixos-codeName})";
  nixos-pretty-name = "NixOS ${nixos-version}";

  stockholm-version = "${config.krebs.os-release.stockholm-version-id}";
  stockholm-pretty-name = "stockholm ${stockholm-version}";

  version = "${stockholm-version}/${nixos-version}";
  version-id = "${config.krebs.os-release.stockholm-version-id}/${nixos-version-id}";
  pretty-name = "${stockholm-pretty-name} / ${nixos-pretty-name}";

  home-url = http://cgit.ni.krebsco.de/stockholm;
in
{
  options.krebs.os-release = {
    stockholm-version-id = lib.mkOption {
      type = lib.types.str;
      default = let
          eval = builtins.tryEval (removeSuffix "\n" (readFile <stockholm-version>));
        in
          if eval.success then eval.value else "unknown";
    };
  };
  config = {
    # http://0pointer.de/public/systemd-man/os-release.html
    environment.etc."os-release".text = mkForce ''
      NAME="stockholm/NixOS"
      ID=stockholm
      VERSION="${version}"
      VERSION_ID="${version-id}"
      PRETTY_NAME="${pretty-name}"
      HOME_URL="${home-url}"
    '';
  };
}