From 40a3f7f47138ddf799112d69a94c64230147b929 Mon Sep 17 00:00:00 2001 From: "info@data-pro.nu" Date: Tue, 3 Mar 2026 11:09:56 +0100 Subject: [PATCH] Added start- end end-scripts --- henrovnix_ok/README.org | 79 +++++++++++++------ .../{recreate_config.sh => copy_stuff.sh} | 4 +- henrovnix_ok/assets/scripts/end_script.sh | 12 +++ henrovnix_ok/assets/scripts/start_script.sh | 12 +++ 4 files changed, 79 insertions(+), 28 deletions(-) rename henrovnix_ok/assets/scripts/{recreate_config.sh => copy_stuff.sh} (79%) create mode 100755 henrovnix_ok/assets/scripts/end_script.sh create mode 100755 henrovnix_ok/assets/scripts/start_script.sh diff --git a/henrovnix_ok/README.org b/henrovnix_ok/README.org index 862e58745..1326dc3b6 100755 --- a/henrovnix_ok/README.org +++ b/henrovnix_ok/README.org @@ -703,10 +703,26 @@ We also add a devshell that makes editing this repository easier in emacs. name = machine; value = lib.nixosSystem { modules = [ + # Start_script.nix + ({ lib, config, pkgs, ... }: { + imports = [ ./start_script.nix ]; + }) <> <> <> catppuccin.nixosModules.catppuccin # theme + + # end_script as a systemd service + ({ lib, config, pkgs, ... }: { + systemd.user.services.endScript = lib.mkIf (lib.fileExists ./assets/scripts/end_script.sh) { + description = "Run end script after Home Manager"; + wantedBy = [ "multi-user.target" ]; + after = [ "home-manager-activate.service" ]; + serviceConfig.Type = "oneshot"; + script = '' + ${./assets/scripts/end_script.sh} + ''; + }; ]; specialArgs = { @@ -894,6 +910,44 @@ This section describes the main system configuration for the computers that I ha } #+end_src +** start_script.nix.nix +#+begin_src nix :tangle start_script.nix :noweb tangle :mkdirp yes +{ lib, config, pkgs, ... }: +let + scriptPath = ./assets/scripts/start_script.sh; + scriptExists = lib.fileExists "${scriptPath}"; +in +{ + system.activationScripts.startScript = lib.mkIf scriptExists { + text = '' + ${scriptPath} + ''; + defer = false; # Run as early as possible + }; +} + +#+end_src + +** end_script.nix.nix +#+begin_src nix :tangle end_script.nix :noweb tangle :mkdirp yes +{ lib, config, pkgs, ... }: +let + scriptPath = ./assets/scripts/end_script.sh; + scriptExists = lib.fileExists "${scriptPath}"; +in +{ + systemd.user.services.endScript = lib.mkIf scriptExists { + description = "Run end script after Home Manager"; + wantedBy = [ "multi-user.target" ]; + after = [ "home-manager-activate.service" ]; + serviceConfig.Type = "oneshot"; + script = '' + ${scriptPath} + ''; + }; +} +#+end_src + ** Apps section This section describes a way of installing packages, either through nixpkgs or flatpak. What extra apps to install is decided in the files ./assets/conf/apps/packages.conf and flatpaks.conf. @@ -2904,31 +2958,6 @@ This is mostly about configuring the monitor. And laptop specific utilities. } #+end_src -* Copy Files 2 homefolder -This makes sure all ./assets/copy_stuff ends up in the right folder -#+begin_src nix :tangle home/copy_stuff.nix :noweb tangle :mkdirp yes. -{ config, pkgs, lib, flakeRoot, ... }: -{ - home.activation.recreateConfig = { - text = '' - #!${pkgs.bash}/bin/bash - set -euo pipefail - SOURCE_DIR="${flakeRoot}/assets/copy_stuff" - DEST_DIR="$HOME" - if [ ! -d "$SOURCE_DIR" ]; then - echo "Error: Source directory $SOURCE_DIR does not exist." - exit 1 - fi - mkdir -p "$DEST_DIR" - rsync -av --no-group --no-owner --delete "$SOURCE_DIR/" "$DEST_DIR/" - echo "Config files copied from $SOURCE_DIR to $DEST_DIR. Symlinks replaced with editable files." - hyprctl reload - ''; - deps = [ pkgs.bash pkgs.rsync ]; - }; -} -#+end_src - * README Utils *** Headers This script adds a =DO NOT MODIFY= header to all the generated nix files. diff --git a/henrovnix_ok/assets/scripts/recreate_config.sh b/henrovnix_ok/assets/scripts/copy_stuff.sh similarity index 79% rename from henrovnix_ok/assets/scripts/recreate_config.sh rename to henrovnix_ok/assets/scripts/copy_stuff.sh index 7cbede9a0..dfe7f3228 100755 --- a/henrovnix_ok/assets/scripts/recreate_config.sh +++ b/henrovnix_ok/assets/scripts/copy_stuff.sh @@ -8,10 +8,8 @@ if [ ! -d "$SOURCE_DIR" ]; then echo "Error: Source directory $SOURCE_DIR does not exist." exit 1 fi -# Create destination directory if it doesn't exist -mkdir -p "$DEST_DIR" # Use rsync to copy files, overwriting symlinks and existing files # --delete removes files in DEST_DIR that are not in SOURCE_DIR # --no-group --no-owner preserves your user ownership -rsync -av --no-group --no-owner --delete "$SOURCE_DIR/" "$DEST_DIR/" +rsync -av --no-group --no-owner "$SOURCE_DIR/" "$DEST_DIR/" echo "Config files copied from $SOURCE_DIR to $DEST_DIR. Symlinks replaced with editable files." diff --git a/henrovnix_ok/assets/scripts/end_script.sh b/henrovnix_ok/assets/scripts/end_script.sh new file mode 100755 index 000000000..8f888f1e4 --- /dev/null +++ b/henrovnix_ok/assets/scripts/end_script.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail +# Example of how to execute a script +# Path to the script to execute +COPY_SCRIPT="./assets/scripts/copy_stuff.sh" +# Check if the script exists +if [ ! -f "$COPY_SCRIPT" ]; then + echo "Error: Script $COPY_SCRIPT does not exist." + exit 1 +fi +# Execute the script +"$COPY_SCRIPT" diff --git a/henrovnix_ok/assets/scripts/start_script.sh b/henrovnix_ok/assets/scripts/start_script.sh new file mode 100755 index 000000000..b382f0830 --- /dev/null +++ b/henrovnix_ok/assets/scripts/start_script.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail +# Example of how to execute a script +# Path to the script to execute +#COPY_SCRIPT="./assets/scripts/copy_stuff.sh" +# Check if the script exists +#if [ ! -f "$COPY_SCRIPT" ]; then +# echo "Error: Script $COPY_SCRIPT does not exist." +#$ exit 1 +#fi +# Execute the script +#"$COPY_SCRIPT"