diff --git a/flake.lock b/flake.lock index a4be078..9498f99 100644 --- a/flake.lock +++ b/flake.lock @@ -1,43 +1,42 @@ { "nodes": { - "devenv": { - "inputs": { - "flake-compat": "flake-compat", - "nix": "nix", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" - }, + "crane": { "locked": { - "lastModified": 1680271030, - "narHash": "sha256-w1Y/S3TylKylTHCp+YkOJbiAE2LBBF1sKIKuLDW4fkU=", - "owner": "cachix", - "repo": "devenv", - "rev": "52232ba41b7c531eacec4cf192d87241bef1a0d1", + "lastModified": 1738636942, + "narHash": "sha256-DJxR9JrloFKYKFblX3ji/Dxv5S/QTXgytEEEycxQeVs=", + "owner": "ipetkov", + "repo": "crane", + "rev": "83be6c2350b607aa58c1b281b400c96d85a64fbe", "type": "github" }, "original": { - "owner": "cachix", - "repo": "devenv", + "owner": "ipetkov", + "repo": "crane", "type": "github" } }, - "flake-compat": { - "flake": false, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": [] + }, "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "lastModified": 1738564312, + "narHash": "sha256-awAp1Qe+c95PQxP7v+Zfse+w3URaP3UQLCRlaPMzYtE=", + "owner": "nix-community", + "repo": "fenix", + "rev": "d99d2a562b9c9d5f0e4399e5bb677b37a791c7eb", "type": "github" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", + "owner": "nix-community", + "repo": "fenix", "type": "github" } }, - "flake-compat_2": { + "flake-compat": { "flake": false, "locked": { "lastModified": 1673956053, @@ -68,25 +67,9 @@ "type": "github" } }, - "flake-utils_2": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "gitignore": { "inputs": { "nixpkgs": [ - "devenv", "pre-commit-hooks", "nixpkgs" ] @@ -105,134 +88,23 @@ "type": "github" } }, - "gitignore_2": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "lowdown-src": { - "flake": false, - "locked": { - "lastModified": 1633514407, - "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", - "owner": "kristapsdz", - "repo": "lowdown", - "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", - "type": "github" - }, - "original": { - "owner": "kristapsdz", - "repo": "lowdown", - "type": "github" - } - }, - "naersk": { - "inputs": { - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1679567394, - "narHash": "sha256-ZvLuzPeARDLiQUt6zSZFGOs+HZmE+3g4QURc8mkBsfM=", - "owner": "nix-community", - "repo": "naersk", - "rev": "88cd22380154a2c36799fe8098888f0f59861a15", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "naersk", - "type": "github" - } - }, - "nix": { - "inputs": { - "lowdown-src": "lowdown-src", - "nixpkgs": [ - "devenv", - "nixpkgs" - ], - "nixpkgs-regression": "nixpkgs-regression" - }, - "locked": { - "lastModified": 1676545802, - "narHash": "sha256-EK4rZ+Hd5hsvXnzSzk2ikhStJnD63odF7SzsQ8CuSPU=", - "owner": "domenkozar", - "repo": "nix", - "rev": "7c91803598ffbcfe4a55c44ac6d49b2cf07a527f", - "type": "github" - }, - "original": { - "owner": "domenkozar", - "ref": "relaxed-flakes", - "repo": "nix", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1678875422, - "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=", - "owner": "NixOS", + "lastModified": 1738638087, + "narHash": "sha256-/7ca2vzDxLmeKZKeRA0yH9sJgWVjlX2Swyph1WeQiac=", + "owner": "sekunho", "repo": "nixpkgs", - "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459", + "rev": "90941712b56ecded7494a20de79fa0ac1ea15cf1", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", + "owner": "sekunho", + "ref": "feat/sqitch-sqlite", "repo": "nixpkgs", "type": "github" } }, - "nixpkgs-regression": { - "locked": { - "lastModified": 1643052045, - "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - } - }, "nixpkgs-stable": { - "locked": { - "lastModified": 1673800717, - "narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-22.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-stable_2": { "locked": { "lastModified": 1678872516, "narHash": "sha256-/E1YwtMtFAu2KUQKV/1+KFuReYPANM2Rzehk84VxVoc=", @@ -249,36 +121,6 @@ } }, "nixpkgs_2": { - "locked": { - "lastModified": 1680273054, - "narHash": "sha256-Bs6/5LpvYp379qVqGt9mXxxx9GSE789k3oFc+OAL07M=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3364b5b117f65fe1ce65a3cdd5612a078a3b31e3", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1680213900, - "narHash": "sha256-cIDr5WZIj3EkKyCgj/6j3HBH4Jj1W296z7HTcWj1aMA=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "e3652e0735fbec227f342712f180f4f21f0594f2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_4": { "locked": { "lastModified": 1680213900, "narHash": "sha256-cIDr5WZIj3EkKyCgj/6j3HBH4Jj1W296z7HTcWj1aMA=", @@ -296,40 +138,12 @@ }, "pre-commit-hooks": { "inputs": { - "flake-compat": [ - "devenv", - "flake-compat" - ], + "flake-compat": "flake-compat", "flake-utils": "flake-utils", "gitignore": "gitignore", - "nixpkgs": [ - "devenv", - "nixpkgs" - ], + "nixpkgs": "nixpkgs_2", "nixpkgs-stable": "nixpkgs-stable" }, - "locked": { - "lastModified": 1678376203, - "narHash": "sha256-3tyYGyC8h7fBwncLZy5nCUjTJPrHbmNwp47LlNLOHSM=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "1a20b9708962096ec2481eeb2ddca29ed747770a", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "pre-commit-hooks_2": { - "inputs": { - "flake-compat": "flake-compat_2", - "flake-utils": "flake-utils_2", - "gitignore": "gitignore_2", - "nixpkgs": "nixpkgs_4", - "nixpkgs-stable": "nixpkgs-stable_2" - }, "locked": { "lastModified": 1680170909, "narHash": "sha256-FtKU/edv1jFRr/KwUxWTYWXEyj9g8GBrHntC2o8oFI8=", @@ -346,10 +160,10 @@ }, "root": { "inputs": { - "devenv": "devenv", - "naersk": "naersk", - "nixpkgs": "nixpkgs_3", - "pre-commit-hooks": "pre-commit-hooks_2" + "crane": "crane", + "fenix": "fenix", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" } } }, diff --git a/flake.nix b/flake.nix index 8f39e7b..fd93234 100644 --- a/flake.nix +++ b/flake.nix @@ -2,46 +2,63 @@ description = "A URL shortener, except emojis"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - devenv.url = "github:cachix/devenv"; - naersk.url = "github:nix-community/naersk"; + nixpkgs.url = "github:sekunho/nixpkgs?ref=feat/sqitch-sqlite"; pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + + crane.url = "github:ipetkov/crane"; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.rust-analyzer-src.follows = ""; + }; }; - outputs = { self, nixpkgs, devenv, naersk, pre-commit-hooks } @ inputs: ( - let system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; + outputs = { self, nixpkgs, pre-commit-hooks, crane, fenix } @ inputs: ( + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; - naersk-lib = naersk.lib.${system}.override { - cargo = pkgs.cargo; - rustc = pkgs.rustc; - }; + craneLib = (crane.mkLib pkgs).overrideToolchain + fenix.packages.${system}.stable.toolchain; - shell = import ./nix/shell.nix { - inherit pkgs; - }; + src = pkgs.lib.cleanSourceWith { + src = ./.; - emojied = import ./nix/modules/packages/emojied.nix { - inherit pkgs; - inherit naersk-lib; - }; + filter = path: type: + (craneLib.filterCargoSources path type) + ; + }; + + commonArgs = { + inherit src; + version = "0.1.5"; + strictDeps = true; + pname = "emojied"; + name = "emojied"; + buildInputs = [ pkgs.openssl ]; + nativeBuildInputs = [ ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; - buildDockerImage = tag: pkgs.dockerTools.buildImage { - name = "emojied-docker"; - tag = tag; - contents = [ pkgs.bash ]; + emojied = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + doCheck = false; + CARGO_PROFILE = "release"; + }); - config = { - Cmd = [ "${self.packages.x86_64-linux.emojied}/bin/run" ]; - WorkingDir = "/app"; - Env = [ "PATH=${pkgs.coreutils}/bin/:${self.packages.${system}.emojied}/bin" ]; + emojied-image = pkgs.dockerTools.streamLayeredImage { + name = "emojied"; + tag = "latest"; + contents = [ self.packages.${system}.emojied ]; - ExposedPorts = { - "3000/tcp" = {}; - }; - }; + config = { + Cmd = [ "/bin/emojied" ]; }; - in { + }; + in + { # checks = { # pre-commit-check = pre-commit-hooks.lib.${system}.run { # src = ./.; @@ -68,9 +85,7 @@ ''; }; - # https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/docker/examples.nix - emojied-docker = buildDockerImage "latest"; - + emojied-docker = emojied-image; default = self.packages.${system}.emojied; }; @@ -81,14 +96,7 @@ }; nixosModules.default = import ./nix/modules/services/emojied.nix; - - devShells.${system}.default = devenv.lib.mkShell { - inherit inputs pkgs; - - modules = [ - ./nix/shell.nix - ]; - }; + devShells.${system}.default = craneLib.devShell (import ./nix/shell.nix { inherit pkgs; }); } ); } diff --git a/nix/shell.nix b/nix/shell.nix index 023f466..b20ca56 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -1,70 +1,19 @@ { pkgs, ... }: rec { - env = { - PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; - PG__DBNAME = "emojied_development"; - PG__HOST = "127.0.0.1"; - PG__USER = "emojied"; - PG__PASSWORD = "emojied"; - PG__PORT = 5433; - APP__STATIC_ASSETS = "./public"; - }; - - packages = with pkgs; [ + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + PG__DBNAME = "emojied_development"; + PG__HOST = "127.0.0.1"; + PG__USER = "emojied"; + PG__PASSWORD = "emojied"; + PG__PORT = 5433; + APP__STATIC_ASSETS = "./public"; + + buildInputs = with pkgs; [ nodePackages.tailwindcss esbuild openssl pkg-config - sqitchPg - perl534Packages.TAPParserSourceHandlerpgTAP + nil + nixpkgs-fmt ]; - - languages = { - rust.enable = true; - typescript.enable = true; - }; - - services.postgres = { - enable = true; - port = env.PG__PORT; - package = pkgs.postgresql_15; - listen_addresses = env.PG__HOST; - initialDatabases = [ { name = env.PG__DBNAME; } ]; - - initialScript = '' - CREATE USER ${env.PG__USER} SUPERUSER PASSWORD '${env.PG__PASSWORD}'; - ''; - }; } - -/* pkgs.mkShell { */ -/* buildInputs = with pkgs; [ */ -/* # Back-end */ -/* rustc */ -/* cargo */ -/* cargo-flamegraph */ - -/* # Front-end */ -/* nodePackages.typescript */ -/* nodePackages.typescript-language-server */ -/* nodePackages.tailwindcss */ -/* esbuild */ - -/* openssl */ -/* pkg-config */ - -/* # Database */ -/* sqitchPg */ -/* perl534Packages.TAPParserSourceHandlerpgTAP */ - -/* # Dev tools */ -/* rust-analyzer */ -/* clippy */ -/* rustfmt */ -/* cargo-watch */ -/* flyctl */ -/* zip */ -/* ]; */ - - -/* } */