From 069236027c8baaf9802915cb048cfcb9efd1df75 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 6 Apr 2024 23:05:17 +0200 Subject: [PATCH] meta: add build info to motd / system label, remove /etc/haccfiles --- flake.nix | 2 +- modules/buildinfo.nix | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 modules/buildinfo.nix diff --git a/flake.nix b/flake.nix index 4b1bc5b..3c83f3b 100644 --- a/flake.nix +++ b/flake.nix @@ -58,9 +58,9 @@ system = "x86_64-linux"; modules = [ ./parsons/configuration.nix + ./modules/buildinfo.nix sops-nix.nixosModules.sops { nixpkgs.pkgs = pkgs; } - { environment.etc."haccfiles".source = self.outPath; } ]; specialArgs = { sources = inputs; diff --git a/modules/buildinfo.nix b/modules/buildinfo.nix new file mode 100644 index 0000000..7ef060f --- /dev/null +++ b/modules/buildinfo.nix @@ -0,0 +1,30 @@ +{ config, lib, pkgs, sources, ... }: + +let + self = sources.self; + slice = string: start: length: with lib; + strings.concatStrings + (lists.take length + (lists.drop start + (strings.stringToCharacters string))); + + formatDate = date: + let + year = slice date 0 4; + month = slice date 4 2; + day = slice date 6 2; + hour = slice date 8 2; + minute = slice date 10 2; + second = slice date 12 2; + in + "${year}-${month}-${day} ${hour}:${minute}:${second} UTC"; +in +{ + system.nixos.label = "${config.system.nixos.release}-haccfiles-${self.shortRev or self.dirtyShortRev}"; + users.motd = '' + Welcome to ${config.networking.hostName}, running NixOS ${config.system.nixos.release}! + Built from haccfiles ${self.rev or self.dirtyRev}. + Last commit was at ${formatDate self.lastModifiedDate}. + ${if self ? dirtyRev then "\nPlease remember to commit your changes.\n" else ""} + ''; +}