Added start- end end-scripts

This commit is contained in:
2026-03-03 11:09:56 +01:00
parent c71a881a0a
commit 40a3f7f471
4 changed files with 79 additions and 28 deletions
+54 -25
View File
@@ -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 ];
})
<<flake-emacs-module>>
<<flake-config-module>>
<<flake-home-module>>
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.
@@ -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."
+12
View File
@@ -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"
+12
View File
@@ -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"