Alternative ATProto PDS implementation

rewrite flake.nix to use crane and rust nightly overlay

Changed files
+148 -138
.nix
-53
.nix/flake.nix
··· 1 - 2 - { 3 - description = "Alternative Bluesky PDS implementation"; 4 - inputs = { 5 - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 6 - flake-utils.url = "github:numtide/flake-utils"; 7 - rust-overlay = { 8 - url = "github:oxalica/rust-overlay"; 9 - inputs = { 10 - nixpkgs.follows = "nixpkgs"; 11 - flake-utils.follows = "flake-utils"; 12 - }; 13 - }; 14 - }; 15 - outputs = { self, nixpkgs, flake-utils, rust-overlay }: 16 - flake-utils.lib.eachDefaultSystem 17 - (system: 18 - let 19 - buildInputs = with pkgs; [ 20 - openssl 21 - gcc 22 - bacon 23 - sqlite 24 - rust-analyzer 25 - rustfmt 26 - clippy 27 - git 28 - nixd 29 - direnv 30 - ]; 31 - overlays = [ (import rust-overlay) ]; 32 - pkgs = import nixpkgs { 33 - inherit system overlays; 34 - }; 35 - rust = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { 36 - extensions = [ 37 - "rust-src" # for rust-analyzer 38 - "rust-analyzer" 39 - ]; 40 - targets = [ "wasm32-unknown-unknown" ]; 41 - }); 42 - nativeBuildInputs = with pkgs; [ rust pkg-config ]; 43 - in 44 - with pkgs; 45 - { 46 - devShells.default = mkShell { 47 - inherit buildInputs nativeBuildInputs; 48 - LD_LIBRARY_PATH = nixpkgs.legacyPackages.x86_64-linux.lib.makeLibraryPath buildInputs; 49 - RUST_BACKTRACE = 1; 50 - DATABASE_URL = "sqlite://data/sqlite.db"; 51 - }; 52 - }); 53 - }
-13
default.nix
··· 1 - { pkgs ? import <nixpkgs> { } }: 2 - pkgs.rustPlatform.buildRustPackage rec { 3 - pname = "bluepds"; 4 - version = "0.0.0"; 5 - cargoLock.lockFile = ./Cargo.lock; 6 - src = pkgs.lib.cleanSource ./.; 7 - nativeBuildInputs = with pkgs; [ pkg-config ]; 8 - buildInputs = with pkgs; [ openssl ]; 9 - postInstall = '' 10 - mkdir -p $out/var/lib/bluepds 11 - cp ./default.toml $out/var/lib/bluepds/ 12 - ''; 13 - }
+148 -57
flake.nix
··· 1 1 { 2 2 description = "Alternative Bluesky PDS implementation"; 3 3 inputs = { 4 - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 4 + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 5 + crane.url = "github:ipetkov/crane"; 6 + flake-utils.url = "github:numtide/flake-utils"; 7 + rust-overlay = { 8 + url = "github:oxalica/rust-overlay"; 9 + inputs.nixpkgs.follows = "nixpkgs"; 10 + }; 5 11 }; 6 - outputs = { self, nixpkgs }: 7 - let 8 - supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; 9 - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; 10 - pkgsFor = nixpkgs.legacyPackages; 11 - in { 12 - packages = forAllSystems (system: { 13 - default = pkgsFor.${system}.callPackage ./. { }; 14 - }); 12 + outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }: 13 + flake-utils.lib.eachDefaultSystem (system: 14 + let 15 + pkgs = import nixpkgs { 16 + inherit system; 17 + overlays = [ (import rust-overlay) ]; 18 + }; 19 + craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)); 20 + 21 + inherit (pkgs) lib; 22 + unfilteredRoot = ./.; # The original, unfiltered source 23 + src = lib.fileset.toSource { 24 + root = unfilteredRoot; 25 + fileset = lib.fileset.unions [ 26 + # Default files from crane (Rust and cargo files) 27 + (craneLib.fileset.commonCargoSources unfilteredRoot) 28 + # Include all the .sql migrations as well 29 + ./migrations 30 + ]; 31 + }; 32 + # Common arguments can be set here to avoid repeating them later 33 + commonArgs = { 34 + inherit src; 35 + strictDeps = true; 36 + nativeBuildInputs = [ 37 + pkgs.pkg-config 38 + ]; 39 + buildInputs = [ 40 + # Add additional build inputs here 41 + pkgs.openssl 42 + ] ++ lib.optionals pkgs.stdenv.isDarwin [ 43 + # Additional darwin specific inputs can be set here 44 + pkgs.libiconv 45 + pkgs.darwin.apple_sdk.frameworks.Security 46 + ]; 47 + 48 + # Additional environment variables can be set directly 49 + # MY_CUSTOM_VAR = "some value"; 50 + }; 51 + 52 + # Build *just* the cargo dependencies, so we can reuse 53 + # all of that work (e.g. via cachix) when running in CI 54 + cargoArtifacts = craneLib.buildDepsOnly commonArgs; 55 + 56 + # Build the actual crate itself, reusing the dependency 57 + # artifacts from above. 58 + bluepds = craneLib.buildPackage (commonArgs // { 59 + inherit cargoArtifacts; 60 + nativeBuildInputs = (commonArgs.nativeBuildInputs or [ ]) ++ [ 61 + pkgs.sqlx-cli 62 + ]; 63 + preBuild = '' 64 + export DATABASE_URL=sqlite://data/sqlite.db 65 + sqlx database create 66 + sqlx migrate run 67 + ''; 68 + postInstall = '' 69 + mkdir -p $out/var/lib/bluepds 70 + cp ./default.toml $out/var/lib/bluepds/ 71 + cp ./sqlite.db $out/var/lib/bluepds/ 72 + ''; 73 + }); 74 + in 75 + { 76 + checks = { 77 + # Build the crate as part of `nix flake check` for convenience 78 + inherit bluepds; 79 + }; 80 + 81 + packages = { 82 + default = bluepds; 83 + inherit bluepds; 84 + }; 85 + 86 + devShells.default = craneLib.devShell { 87 + # Inherit inputs from checks. 88 + checks = self.checks.${system}; 89 + 90 + # Additional dev-shell environment variables can be set directly 91 + # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; 92 + 93 + # Extra inputs can be added here; cargo and rustc are provided by default. 94 + packages = with pkgs; [ 95 + sqlx-cli 96 + bacon 97 + sqlite 98 + rust-analyzer 99 + rustfmt 100 + clippy 101 + git 102 + nixd 103 + direnv 104 + ]; 105 + }; 15 106 16 - nixosModules = { 17 - default = { pkgs, lib, config, ... }: with lib; let 18 - cfg = config.services.bluepds; 19 - in 20 - { 21 - options.services.bluepds = { 22 - enable = mkEnableOption "Enable bluepds"; 23 - host_name = mkOption { 24 - type = types.str; 25 - default = "pds.example.com"; 26 - description = "The public hostname of the PDS."; 27 - }; 28 - listen_address = mkOption { 29 - type = types.str; 30 - default = "0.0.0.0:8000"; 31 - description = "The address to listen to for incoming requests."; 32 - }; 33 - test = mkOption { 34 - type = types.str; 35 - default = "true"; 36 - description = "Test mode. This instructs BluePDS not to federate with the rest of the AT network."; 37 - }; 38 - package = mkOption { 39 - type = types.package; 40 - default = self.packages.${pkgs.system}.default; 41 - description = "The path to the bluepds package."; 42 - }; 43 - }; 44 - config = mkIf cfg.enable { 45 - systemd.services.bluepds = { 46 - description = "ATProto PDS server"; 47 - wantedBy = [ "multi-user.target" ]; 48 - after = [ "network.target" ]; 49 - requires = [ "network-online.target" ]; 50 - environment = { 51 - BLUEPDS_TEST = "${cfg.test}"; 52 - BLUEPDS_HOST_NAME = "${cfg.host_name}"; 53 - BLUEPDS_LISTEN_ADDRESS = "${cfg.listen_address}"; 107 + nixosModules = { 108 + default = { pkgs, lib, config, ... }: with lib; let 109 + cfg = config.services.bluepds; 110 + in 111 + { 112 + options.services.bluepds = { 113 + enable = mkEnableOption "Enable bluepds"; 114 + host_name = mkOption { 115 + type = types.str; 116 + default = "pds.example.com"; 117 + description = "The public hostname of the PDS."; 54 118 }; 55 - serviceConfig = { 56 - ExecStart = "${cfg.package}/bin/bluepds"; 57 - ProtectHome = true; 58 - WorkingDirectory= "/var/lib/bluepds"; 59 - Restart = "on-failure"; 60 - Type = "exec"; 119 + listen_address = mkOption { 120 + type = types.str; 121 + default = "0.0.0.0:8000"; 122 + description = "The address to listen to for incoming requests."; 123 + }; 124 + test = mkOption { 125 + type = types.str; 126 + default = "true"; 127 + description = "Test mode. This instructs BluePDS not to federate with the rest of the AT network."; 128 + }; 129 + package = mkOption { 130 + type = types.package; 131 + default = self.packages.${pkgs.system}.default; 132 + description = "The path to the bluepds package."; 133 + }; 134 + }; 135 + config = mkIf cfg.enable { 136 + systemd.services.bluepds = { 137 + description = "ATProto PDS server"; 138 + wantedBy = [ "multi-user.target" ]; 139 + after = [ "network.target" ]; 140 + requires = [ "network-online.target" ]; 141 + environment = { 142 + BLUEPDS_TEST = "${cfg.test}"; 143 + BLUEPDS_HOST_NAME = "${cfg.host_name}"; 144 + BLUEPDS_LISTEN_ADDRESS = "${cfg.listen_address}"; 145 + }; 146 + serviceConfig = { 147 + ExecStart = "${cfg.package}/bin/bluepds"; 148 + ProtectHome = true; 149 + WorkingDirectory= "/var/lib/bluepds"; 150 + Restart = "on-failure"; 151 + Type = "exec"; 152 + }; 61 153 }; 62 154 }; 63 155 }; 64 - }; 65 - }; 66 - }; 156 + }; 157 + }); 67 158 }
-15
shell.nix
··· 1 - 2 - { pkgs ? import <nixpkgs> { } }: 3 - pkgs.mkShell { 4 - inputsFrom = [ (pkgs.callPackage ./default.nix { }) ]; 5 - buildInputs = with pkgs; [ 6 - bacon 7 - sqlite 8 - rust-analyzer 9 - rustfmt 10 - clippy 11 - git 12 - nixd 13 - direnv 14 - ]; 15 - }