From 0fdd56c432a51d10fb057a67f72228ca9b56d33c Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 3 May 2025 16:15:57 +1000 Subject: [PATCH] nix: automatically pull dotfiles and apply them on boot --- nix/flake.nix | 1 + nix/modules/stow.nix | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 nix/modules/stow.nix diff --git a/nix/flake.nix b/nix/flake.nix index 47d73a0..442babd 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -19,6 +19,7 @@ ./modules/firefox.nix ./modules/games.nix ./modules/boot.nix + ./modules/stow.nix ./hosts/pluto/conf.nix ./hosts/pluto/hardware-configuration.nix diff --git a/nix/modules/stow.nix b/nix/modules/stow.nix new file mode 100644 index 0000000..59d9941 --- /dev/null +++ b/nix/modules/stow.nix @@ -0,0 +1,35 @@ +{ config, lib, pkgs, ... }: + + +{ + systemd.user.services.stowinit = { + enable = true; + after = [ "network.target" ]; + wantedBy = [ "default.target" ]; + description = "apply stow configurations and pull dotfiles."; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + + script = '' + export installdir="$HOME/dots" + export repo="https://codeberg.org/nico/dots" + + if [ ! -d "$installdir" ]; then + echo "cloning repo" + ${pkgs.git}/bin/git clone $repo $installdir + else + echo "pulling latest dotfiles" + + pushd $installdir + ${pkgs.git}/bin/git pull $repo # works if repo is cloned using ssh + popd + fi + + ${pkgs.stow}/bin/stow --target=$HOME --dir=$installdir stow + echo "stowed configuration!" + ''; + }; + +}