diff options
author | Martin Fischer <martin@push-f.com> | 2025-04-04 15:07:55 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-04-05 12:10:36 +0200 |
commit | d8b675d3670a70df15ec46dfd9a1bb9f801aae41 (patch) | |
tree | 9a8d5188081c912ba463ad06f005983ad82d6836 | |
parent | b6e94ce2128968d83b0714904b251de434b58ab2 (diff) |
build: introduce Nix package and NixOS service
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | default.nix | 13 | ||||
-rwxr-xr-x | deploy.sh | 2 | ||||
-rw-r--r-- | service.nix | 53 |
4 files changed, 67 insertions, 2 deletions
@@ -1,3 +1,4 @@ caniuse.rs/ rust/ out/ +result diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..01d0210 --- /dev/null +++ b/default.nix @@ -0,0 +1,13 @@ +{ pkgs ? import <nixpkgs> {} }: + +pkgs.buildGoModule rec { + pname = "rust-features"; + version = "git"; + src = ./.; + vendorHash = "sha256-WaDp7wKYHeV8hAAwPGmp1Dv8Hkwzl+Mzr8yzuUP2TgQ="; + nativeBuildInputs = [pkgs.makeWrapper]; + + postInstall = '' + wrapProgram $out/bin/rust-features --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.git pkgs.bash ]} + ''; +} diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index 0b57bc4..0000000 --- a/deploy.sh +++ /dev/null @@ -1,2 +0,0 @@ -./fetch_and_build.sh -tar cf - -C target . | ssh push-f.com 'sh -c "set -x; cd /var/www/rust-features.push-f.com && pwd && tar xvf - && echo done"' diff --git a/service.nix b/service.nix new file mode 100644 index 0000000..f274ba5 --- /dev/null +++ b/service.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +let + rust_features = pkgs.callPackage ./default.nix {}; + cfg = config.services.rust-features; +in +{ + options.services.rust-features = { + enable = lib.mkEnableOption "rust-features"; + + virtualHost = lib.mkOption { + type = lib.types.str; + description = "Name of the nginx virtualhost to set up."; + }; + + user = lib.mkOption { + type = lib.types.str; + description = "User account under which the rust-features service runs."; + }; + + nginx = lib.mkOption { + type = lib.types.submodule (import <nixpkgs/nixos/modules/services/web-servers/nginx/vhost-options.nix>); + default = {}; + }; + }; + + config = lib.mkIf cfg.enable { + services.nginx = { + enable = true; + + virtualHosts.${cfg.virtualHost} = lib.mkMerge [ + cfg.nginx + { + locations."/" = { + root = "/var/lib/rust-features/out"; + }; + } + ]; + }; + + systemd.services.rust-features = { + serviceConfig = { + Type = "oneshot"; + User = cfg.user; + StateDirectory = "rust-features"; # creates /var/lib/rust-features + WorkingDirectory = "/var/lib/rust-features"; + ExecStart = "${rust_features}/bin/rust-features"; + LogExtraFields = "log_format=logfmt"; + }; + startAt = "hourly"; + }; + }; +} |