127 current 1970-01-01 01:00:00 24.05.20240303.b8697e5 6.6.19 *

This commit is contained in:
Max Känner 2024-03-09 21:09:56 +01:00
parent 8bb06f218b
commit 25c0c31e15
2 changed files with 47 additions and 0 deletions

View File

@ -10,6 +10,8 @@
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
# script for rebuilding nixos
../../modules/nixos/rebuild.nix
# greetd login manager
../../modules/nixos/greetd.nix
# sway as window manager

45
modules/nixos/rebuild.nix Normal file
View File

@ -0,0 +1,45 @@
{pkgs, ...}: let
# script for rebuilding nixos
rebuild = pkgs.writeTextFile {
name = "rebuild";
destination = "/bin/rebuild";
executable = true;
text = ''
#!/usr/bin/env bash
# A rebuild script that commits on a successful build
set -e
# cd to your config dir
pushd ${"../.."}
# Edit your config
$EDITOR
# Autoformat your nix files
${pkgs.alejandra}/bin/alejandra . #&>/dev/null
# Shows your changes
${pkgs.git}/bin/git diff -U0 *.nix
echo "NixOS Rebuilding..."
# Rebuild, output simplified errors, log trackebacks
${pkgs.sudo}/bin/sudo nixos-rebuild switch &>nixos-switch.log || (${pkgs.coreutils}/bin/cat nixos-switch.log | ${pkgs.gnugrep}/bin/grep --color error && false)
# Get current generation metadata
current=$(nixos-rebuild list-generations | ${pkgs.gnugrep}/bin/grep current)
# Commit all changes with the gereation metadata
${pkgs.git}/bin/git commit -am "$current"
# Back to where you were
popd
# Notify all OK!
${pkgs.libnotify}/bin/notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available
'';
};
in {
environment.systemPackages = [rebuild];
}