Refactor pool.nix service script: streamline git symlink creation and remove redundant directory setup

This commit is contained in:
Chris Toph 2025-05-27 14:41:54 -04:00
parent 41ceef3e77
commit 54ad243c75
2 changed files with 6 additions and 33 deletions

View file

@ -3,9 +3,6 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Pin stable vs unstable: use nixpkgs-stable for critical packages while nixpkgs follows the beta branch.
# See overlays "stable-packages" and "unstable-packages" in ./overlays/default.nix.
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.11"; nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
@ -79,21 +76,16 @@
inherit (self) outputs; inherit (self) outputs;
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
ARM = "aarch64-linux"; # ARM systems ARM = "aarch64-linux";
X86 = "x86_64-linux"; # x86_64 systems X86 = "x86_64-linux";
#
# ========= Architectures =========
#
forAllSystems = nixpkgs.lib.genAttrs [ forAllSystems = nixpkgs.lib.genAttrs [
ARM ARM
X86 X86
]; ];
# ## Host Config ##
# ========= Host Config Functions =========
#
# Handle a given host config based on whether its underlying system is nixos or darwin
mkHost = host: isARM: { mkHost = host: isARM: {
${host} = ${host} =
let let
@ -108,14 +100,12 @@
isARM isARM
; ;
system = systemFunc; system = systemFunc;
# ========== Extend lib with lib.custom ========== # INFO: Extend lib with lib.custom; This approach allows lib.custom to propagate into hm
# NOTE: This approach allows lib.custom to propagate into hm
# see: https://github.com/nix-community/home-manager/pull/3454
lib = nixpkgs.lib.extend (self: super: { custom = import ./lib { inherit (nixpkgs) lib; }; }); lib = nixpkgs.lib.extend (self: super: { custom = import ./lib { inherit (nixpkgs) lib; }; });
}; };
modules = [ modules = [
# Apply the overlays to make custom packages available
{ {
#INFO: Overlay application for custom packages
nixpkgs.overlays = [ nixpkgs.overlays = [
self.overlays.default self.overlays.default
]; ];
@ -133,25 +123,13 @@
# Invoke mkHost for each host config that is declared for either X86 or ARM # Invoke mkHost for each host config that is declared for either X86 or ARM
mkHostConfigs = mkHostConfigs =
hosts: isARM: lib.foldl (acc: set: acc // set) { } (lib.map (host: mkHost host isARM) hosts); hosts: isARM: lib.foldl (acc: set: acc // set) { } (lib.map (host: mkHost host isARM) hosts);
# Return the hosts declared in the given directory
readHosts = folder: lib.attrNames (builtins.readDir ./hosts/${folder}); readHosts = folder: lib.attrNames (builtins.readDir ./hosts/${folder});
in in
{ {
#
# ========= Overlays =========
#
# Custom modifications/overrides to upstream packages.
overlays = import ./overlays { inherit inputs; }; overlays = import ./overlays { inherit inputs; };
#
# ========= Host Configurations =========
#
# Building configurations is available through `just rebuild` or `nixos-rebuild --flake .#hostname`
nixosConfigurations = mkHostConfigs (readHosts "nixos") false; nixosConfigurations = mkHostConfigs (readHosts "nixos") false;
# ========= Packages =========
#
# Add custom packages to be shared or upstreamed.
packages = forAllSystems ( packages = forAllSystems (
system: system:
let let

View file

@ -19,12 +19,7 @@ in
requires = [ "pool.mount" ]; requires = [ "pool.mount" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
script = '' script = ''
umount /pool/git
mkdir -p /pool/git
chown ${username}:ryot /pool/git
chmod 2775 /pool/git
ln -sf /pool/git ${homeDir}/git ln -sf /pool/git ${homeDir}/git
chown -h ${username}:ryot ${homeDir}/git
''; '';
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";