From 580f80b521ca3f97dbdd113fa968e0bdb9d0603f Mon Sep 17 00:00:00 2001 From: dolphinau Date: Wed, 27 Aug 2025 18:11:12 +0200 Subject: [PATCH] Improve nix setup --- .gitignore | 26 +++++++++++++++++++++++--- README.md | 25 +++++++++++++++++++++++++ default.nix | 16 ++++++++++++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 41 +++++++++++------------------------------ shell.nix | 11 +++++++++++ 6 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index 0f7fb5b..545d8a5 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,24 @@ -/target -flake.lock -.direnv/ *.env + +target +**/*.rs.bk +.idea +*.iml +/result* +*.log +*~ + +# cachix tmp file +store-path-pre-build + +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml + +template/flake.lock diff --git a/README.md b/README.md index c2fb690..0cfa516 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,31 @@ just init # Will init the database, and build the app image just run # Will run the lwn-sub-snoozer to update the database and the RSS file ``` +## Nix setup + +For my server, I have the following setup: + +```nix +systemd.timers."rssify-update" = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnBootSec = "5m"; + OnUnitActiveSec = "12h"; + Unit = "rssify-update.service"; + }; +}; + +systemd.services."rssify-update" = { + script = '' + ${pkgs.rssify}/bin/echo "Hello World" + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; +}; +``` + ## TODO - [ ] Nix service with timer diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..db713d1 --- /dev/null +++ b/default.nix @@ -0,0 +1,16 @@ +{pkgs ? import {}}: let + manifest = (pkgs.lib.importTOML ./Cargo.toml).package; +in + pkgs.rustPlatform.buildRustPackage { + pname = manifest.name; + version = manifest.version; + cargoLock.lockFile = ./Cargo.lock; + src = pkgs.lib.cleanSource ./.; + + nativeBuildInputs = with pkgs; [ + pkg-config + ]; + buildInputs = with pkgs; [ + openssl + ]; + } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..41ae270 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1756217674, + "narHash": "sha256-TH1SfSP523QI7kcPiNtMAEuwZR3Jdz0MCDXPs7TS8uo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4e7667a90c167f7a81d906e5a75cba4ad8bee620", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 678752a..d632328 100755 --- a/flake.nix +++ b/flake.nix @@ -1,41 +1,22 @@ { description = "lwn-sub-snoozer"; inputs = { - flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; }; outputs = { self, nixpkgs, - flake-utils, - }: - flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; - in { - packages = { - default = self.packages.${system}.myapp; - }; - # $ nix develop - devShells.default = pkgs.mkShell { - LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [pkgs.openssl]; - packages = [ - pkgs.pkg-config - pkgs.openssl - pkgs.postgresql - - # Nix - pkgs.nixpkgs-fmt - pkgs.nil - pkgs.nixd - pkgs.alejandra - - # Rust - pkgs.rustfmt - pkgs.rustc - pkgs.cargo - pkgs.rust-analyzer - ]; - }; + }: let + supportedSystems = ["x86_64-linux"]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgsFor = nixpkgs.legacyPackages; + in { + packages = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./. {}; }); + devShells = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./shell.nix {}; + }); + }; } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..514ec12 --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ +{pkgs ? import {}}: +pkgs.mkShell { + inputsFrom = [(pkgs.callPackage ./default.nix {})]; + buildInputs = with pkgs; [ + rust-analyzer + alejandra + clippy + nixd + nil + ]; +}