at 25.11-pre 4.2 kB view raw
1{ 2 lib, 3 pkgs, 4 config, 5 ... 6}: 7 8let 9 cfg = config.services.pict-rs; 10 inherit (lib) maintainers mkOption types; 11in 12{ 13 meta.maintainers = with maintainers; [ happysalada ]; 14 meta.doc = ./pict-rs.md; 15 16 options.services.pict-rs = { 17 enable = lib.mkEnableOption "pict-rs server"; 18 19 package = lib.mkPackageOption pkgs "pict-rs" { }; 20 21 dataDir = mkOption { 22 type = types.path; 23 default = "/var/lib/pict-rs"; 24 description = '' 25 The directory where to store the uploaded images & database. 26 ''; 27 }; 28 29 repoPath = mkOption { 30 type = types.nullOr (types.path); 31 default = null; 32 description = '' 33 The directory where to store the database. 34 This option takes precedence over dataDir. 35 ''; 36 }; 37 38 storePath = mkOption { 39 type = types.nullOr (types.path); 40 default = null; 41 description = '' 42 The directory where to store the uploaded images. 43 This option takes precedence over dataDir. 44 ''; 45 }; 46 47 address = mkOption { 48 type = types.str; 49 default = "127.0.0.1"; 50 description = '' 51 The IPv4 address to deploy the service to. 52 ''; 53 }; 54 55 port = mkOption { 56 type = types.port; 57 default = 8080; 58 description = '' 59 The port which to bind the service to. 60 ''; 61 }; 62 }; 63 64 config = lib.mkIf cfg.enable { 65 services.pict-rs.package = lib.mkDefault ( 66 if lib.versionAtLeast config.system.stateVersion "23.11" then 67 pkgs.pict-rs 68 else 69 throw '' 70 pict-rs made changes to the database schema between 0.3 and 0.4. It 71 will apply these automatically on the first run of 0.4, but the old 72 version will no longer work after that. 73 74 Your configuration is currently using the old default of pict-rs 75 0.3. Unfortunately, 0.3 no longer builds due to the Rust 1.80 update, 76 and has been removed. pict-rs has already been updated to 0.5 in 77 Nixpkgs, which has another schema change but removes the migration 78 logic for 0.3. 79 80 You will need to migrate to 0.4 first, and then to 0.5. As 0.4 is 81 no longer present in Nixpkgs, the recommended migration path is: 82 83 * Import a separate Nixpkgs old enough to contain 0.4, temporarily 84 set `services.pict-rs.package` to its pict-rs, set the 85 `PICTRS__OLD_DB__PATH` environment variable for the migration, and 86 activate your configuration to start it. The following configuration 87 snippet should work: 88 89 services.pict-rs.package = 90 (import (builtins.fetchTarball { 91 url = "https://github.com/NixOS/nixpkgs/archive/9b19f5e77dd906cb52dade0b7bd280339d2a1f3d.tar.gz"; 92 sha256 = "sha256:0939vbhln9d33xkqw63nsk908k03fxihj85zaf70i3il9z42q8mc"; 93 }) pkgs.config).pict-rs; 94 95 systemd.services.pict-rs.environment.PICTRS__OLD_DB__PATH = config.services.pict-rs.dataDir; 96 97 * After the migration to 0.4 completes, remove the package and 98 environment variable overrides, set `services.pict-rs.package` to 99 the current `pkgs.pict-rs` instead, and activate your configuration 100 to begin the migration to 0.5. 101 102 For more information, see: 103 104 * <https://git.asonix.dog/asonix/pict-rs/src/tag/v0.4.8#0-3-to-0-4-migration-guide> 105 * <https://git.asonix.dog/asonix/pict-rs/src/tag/v0.5.16#0-4-to-0-5-migration-guide> 106 107 The NixOS module will handle the configuration changes for you, 108 at least. 109 '' 110 ); 111 112 systemd.services.pict-rs = { 113 environment = { 114 PICTRS__REPO__PATH = if cfg.repoPath != null then cfg.repoPath else "${cfg.dataDir}/sled-repo"; 115 PICTRS__STORE__PATH = if cfg.storePath != null then cfg.storePath else "${cfg.dataDir}/files"; 116 PICTRS__SERVER__ADDRESS = "${cfg.address}:${toString cfg.port}"; 117 }; 118 wantedBy = [ "multi-user.target" ]; 119 serviceConfig = { 120 DynamicUser = true; 121 StateDirectory = "pict-rs"; 122 ExecStart = "${lib.getBin cfg.package}/bin/pict-rs run"; 123 }; 124 }; 125 }; 126 127}