Improve nix setup

This commit is contained in:
dolphinau 2025-08-27 18:11:12 +02:00
parent 6f85efcd26
commit 580f80b521
No known key found for this signature in database
6 changed files with 113 additions and 33 deletions

26
.gitignore vendored
View file

@ -1,4 +1,24 @@
/target
flake.lock
.direnv/
*.env *.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

View file

@ -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 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 ## TODO
- [ ] Nix service with timer - [ ] Nix service with timer

16
default.nix Normal file
View file

@ -0,0 +1,16 @@
{pkgs ? import <nixpkgs> {}}: 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
];
}

27
flake.lock generated Normal file
View file

@ -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
}

View file

@ -1,41 +1,22 @@
{ {
description = "lwn-sub-snoozer"; description = "lwn-sub-snoozer";
inputs = { inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
}; };
outputs = { outputs = {
self, self,
nixpkgs, nixpkgs,
flake-utils, }: let
}: supportedSystems = ["x86_64-linux"];
flake-utils.lib.eachDefaultSystem (system: let forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = nixpkgs.legacyPackages.${system}; pkgsFor = nixpkgs.legacyPackages;
in { in {
packages = { packages = forAllSystems (system: {
default = self.packages.${system}.myapp; default = pkgsFor.${system}.callPackage ./. {};
};
# $ 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
];
};
}); });
devShells = forAllSystems (system: {
default = pkgsFor.${system}.callPackage ./shell.nix {};
});
};
} }

11
shell.nix Normal file
View file

@ -0,0 +1,11 @@
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
inputsFrom = [(pkgs.callPackage ./default.nix {})];
buildInputs = with pkgs; [
rust-analyzer
alejandra
clippy
nixd
nil
];
}