git bankruptcy
This commit is contained in:
parent
6d45fb2f70
commit
7519eba80c
7 changed files with 201 additions and 26 deletions
95
flake.nix
95
flake.nix
|
|
@ -3,13 +3,15 @@
|
|||
|
||||
# Flake inputs
|
||||
inputs = {
|
||||
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2405.*.tar.gz";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay"; # A helper for Rust + Nix
|
||||
};
|
||||
|
||||
# Flake outputs
|
||||
outputs = { self, nixpkgs, rust-overlay }:
|
||||
let
|
||||
pdsDirectory = "/home/pan/prog/atproto/appview";
|
||||
|
||||
# Overlays enable you to customize the Nixpkgs attribute set
|
||||
overlays = [
|
||||
# Makes a `rust-bin` attribute available in Nixpkgs
|
||||
|
|
@ -33,19 +35,88 @@
|
|||
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
|
||||
pkgs = import nixpkgs { inherit overlays system; };
|
||||
});
|
||||
|
||||
# Systemd service configuration
|
||||
createSystemdService = pkgs: pdsDir: pkgs.writeTextFile {
|
||||
name = "pds.service";
|
||||
text = ''
|
||||
[Unit]
|
||||
Description=Development Environment Service
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=${pkgs.pds}/bin/pds
|
||||
WorkingDirectory=${pdsDir}
|
||||
EnvironmentFile=${pdsDir}/.env
|
||||
Environment=PDS_DATA_DIRECTORY=${pdsDir}/.pds-data
|
||||
Environment=PDS_BLOBSTORE_DISK_LOCATION=${pdsDir}/.pds-data/blocks
|
||||
'';
|
||||
};
|
||||
|
||||
# Scripts for managing the systemd service
|
||||
createServiceScripts = pkgs: pdsDir:
|
||||
let
|
||||
serviceFile = createSystemdService pkgs pdsDir;
|
||||
serviceName = "pds";
|
||||
in {
|
||||
startScript = pkgs.writeShellScript "start-dev-service" ''
|
||||
set -e
|
||||
|
||||
# Create user systemd directory if it doesn't exist
|
||||
mkdir -p ~/.config/systemd/user
|
||||
|
||||
# Copy service file
|
||||
cp -f ${serviceFile} ~/.config/systemd/user/${serviceName}.service
|
||||
|
||||
# Reload systemd and start service
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user start ${serviceName}
|
||||
systemctl --user enable ${serviceName}
|
||||
|
||||
systemctl --user status ${serviceName} --no-pager
|
||||
'';
|
||||
|
||||
stopScript = pkgs.writeShellScript "stop-dev-service" ''
|
||||
set -e
|
||||
if systemctl --user is-enabled --quiet ${serviceName}; then
|
||||
# Stop and disable service
|
||||
systemctl --user stop ${serviceName} || true
|
||||
systemctl --user disable ${serviceName} || true
|
||||
|
||||
# Remove service file
|
||||
rm -f ~/.config/systemd/user/${serviceName}.service
|
||||
|
||||
# Reload systemd
|
||||
systemctl --user daemon-reload
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
# Development environment output
|
||||
devShells = forAllSystems ({ pkgs }: {
|
||||
default = pkgs.mkShell {
|
||||
# The Nix packages provided in the environment
|
||||
packages = (with pkgs; [
|
||||
# The package provided by our custom overlay. Includes cargo, Clippy, cargo-fmt,
|
||||
# rustdoc, rustfmt, and other tools.
|
||||
sqlx-cli
|
||||
rustToolchain
|
||||
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
|
||||
};
|
||||
});
|
||||
devShells = forAllSystems ({ pkgs }:
|
||||
let
|
||||
scripts = createServiceScripts pkgs pdsDirectory;
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
# The Nix packages provided in the environment
|
||||
packages = (with pkgs; [
|
||||
# The package provided by our custom overlay. Includes cargo, Clippy, cargo-fmt,
|
||||
# rustdoc, rustfmt, and other tools.
|
||||
sqlx-cli
|
||||
rustToolchain
|
||||
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
|
||||
|
||||
shellHook = pkgs.lib.optionalString pkgs.stdenv.isLinux ''
|
||||
# Cleanup
|
||||
${scripts.stopScript}
|
||||
|
||||
# Start the systemd service
|
||||
${scripts.startScript}
|
||||
'';
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue