From 08de19a03d7584a9d3218abc58d5ba853e695667 Mon Sep 17 00:00:00 2001 From: SEKUN Date: Sun, 2 Apr 2023 18:08:50 +0800 Subject: [PATCH] chore(nix): Add devenv to nix and redo nix setup (#29) --- .envrc | 2 +- .gitignore | 2 + flake.lock | 213 +++++++++++++++++++++++++++++-- flake.nix | 20 +-- nix/modules/packages/emojied.nix | 10 +- nix/shell.nix | 97 +++++++++----- sqitch.conf | 2 +- 7 files changed, 289 insertions(+), 57 deletions(-) diff --git a/.envrc b/.envrc index 3550a30..cffc922 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake +use flake . --impure diff --git a/.gitignore b/.gitignore index f7992d6..e3bb28d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ public/app.css # flamegraph perf.data* flamegraph.svg + +.devenv diff --git a/flake.lock b/flake.lock index 31aeb73..b678597 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,26 @@ { "nodes": { + "devenv": { + "inputs": { + "flake-compat": "flake-compat", + "nix": "nix", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1680271030, + "narHash": "sha256-w1Y/S3TylKylTHCp+YkOJbiAE2LBBF1sKIKuLDW4fkU=", + "owner": "cachix", + "repo": "devenv", + "rev": "52232ba41b7c531eacec4cf192d87241bef1a0d1", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -16,6 +37,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1667395993, @@ -31,7 +68,44 @@ "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" + ] + }, + "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" + } + }, + "gitignore_2": { "inputs": { "nixpkgs": [ "pre-commit-hooks", @@ -52,6 +126,22 @@ "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": [ @@ -72,13 +162,37 @@ "type": "github" } }, - "nixos-unstable": { + "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" + } + }, + "nixospkgs": { "locked": { - "lastModified": 1647893727, - "narHash": "sha256-pOi7VdCb+s5Cwh5CS7YEZVRgH9uCmE87J5W7iXv29Ck=", + "lastModified": 1680213900, + "narHash": "sha256-cIDr5WZIj3EkKyCgj/6j3HBH4Jj1W296z7HTcWj1aMA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1ec61dd4167f04be8d05c45780818826132eea0d", + "rev": "e3652e0735fbec227f342712f180f4f21f0594f2", "type": "github" }, "original": { @@ -90,20 +204,53 @@ }, "nixpkgs": { "locked": { - "lastModified": 1680343703, - "narHash": "sha256-r9U3n9codXHR+I6zLYbvxaD/2MrJHpPtJWsnCW212js=", + "lastModified": 1678875422, + "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9448487d9f7056253ecadfdab7d7bdc638191de2", + "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "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=", @@ -119,16 +266,59 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1680343703, + "narHash": "sha256-r9U3n9codXHR+I6zLYbvxaD/2MrJHpPtJWsnCW212js=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9448487d9f7056253ecadfdab7d7bdc638191de2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { - "flake-compat": "flake-compat", + "flake-compat": [ + "devenv", + "flake-compat" + ], "flake-utils": "flake-utils", "gitignore": "gitignore", "nixpkgs": [ + "devenv", "nixpkgs" ], "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" + ], + "nixpkgs-stable": "nixpkgs-stable_2" + }, "locked": { "lastModified": 1680170909, "narHash": "sha256-FtKU/edv1jFRr/KwUxWTYWXEyj9g8GBrHntC2o8oFI8=", @@ -145,10 +335,11 @@ }, "root": { "inputs": { + "devenv": "devenv", "naersk": "naersk", - "nixos-unstable": "nixos-unstable", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" + "nixospkgs": "nixospkgs", + "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": "pre-commit-hooks_2" } } }, diff --git a/flake.nix b/flake.nix index 0f2053f..575e278 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,10 @@ { - # Min nix version: 2.7.0 description = "A URL shortener, except emojis"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; - nixos-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixospkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + devenv.url = "github:cachix/devenv"; naersk = { url = "github:nix-community/naersk"; @@ -17,10 +17,9 @@ }; }; - outputs = { self, nixpkgs, nixos-unstable, naersk, pre-commit-hooks }: ( + outputs = { self, nixpkgs, nixospkgs, devenv, naersk, pre-commit-hooks } @ inputs: ( let system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - unstablepkgs = nixos-unstable.legacyPackages.${system}; + pkgs = nixospkgs.legacyPackages.${system}; naersk-lib = naersk.lib.${system}.override { cargo = pkgs.cargo; @@ -29,12 +28,10 @@ shell = import ./nix/shell.nix { inherit pkgs; - inherit unstablepkgs; }; emojied = import ./nix/modules/packages/emojied.nix { inherit pkgs; - inherit unstablepkgs; inherit naersk-lib; }; @@ -93,7 +90,14 @@ }; nixosModule = import ./nix/modules/services/emojied.nix; - devShells.${system}.default = shell; + + devShells.${system}.default = devenv.lib.mkShell { + inherit inputs pkgs; + + modules = [ + ./nix/shell.nix + ]; + }; } ); } diff --git a/nix/modules/packages/emojied.nix b/nix/modules/packages/emojied.nix index 4330e12..8af3ce3 100644 --- a/nix/modules/packages/emojied.nix +++ b/nix/modules/packages/emojied.nix @@ -1,16 +1,16 @@ -{ pkgs, unstablepkgs, naersk-lib }: +{ pkgs, naersk-lib }: (naersk-lib.buildPackage { pname = "emojied"; - version = "0.1.3"; + version = "0.1.4"; root = ../../../.; nativeBuildInputs = with pkgs; [ ]; buildInputs = with pkgs; [ openssl pkg-config ]; }).overrideAttrs (old: { nativeBuildInputs = old.nativeBuildInputs ++ [ - unstablepkgs.nodePackages.typescript - unstablepkgs.nodePackages.tailwindcss - unstablepkgs.esbuild + pkgs.nodePackages.typescript + pkgs.nodePackages.tailwindcss + pkgs.esbuild ]; doCheck = true; diff --git a/nix/shell.nix b/nix/shell.nix index cff39bb..023f466 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -1,35 +1,70 @@ -{ pkgs, unstablepkgs }: - -pkgs.mkShell { - buildInputs = [ - # Back-end - pkgs.rustc - pkgs.cargo - unstablepkgs.cargo-flamegraph - - # Front-end - unstablepkgs.nodePackages.typescript - unstablepkgs.nodePackages.typescript-language-server - unstablepkgs.nodePackages.tailwindcss - unstablepkgs.esbuild - - pkgs.openssl - pkgs.pkg-config - - # Database - pkgs.sqitchPg - pkgs.perl534Packages.TAPParserSourceHandlerpgTAP - - # Dev tools - pkgs.rust-analyzer - pkgs.clippy - pkgs.rustfmt - pkgs.cargo-watch - pkgs.flyctl - pkgs.zip +{ 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; [ + nodePackages.tailwindcss + esbuild + openssl + pkg-config + + sqitchPg + perl534Packages.TAPParserSourceHandlerpgTAP ]; - PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + 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; } ]; - APP__STATIC_ASSETS = ""; + 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 */ +/* ]; */ + + +/* } */ diff --git a/sqitch.conf b/sqitch.conf index 5b113dc..1f65bfe 100644 --- a/sqitch.conf +++ b/sqitch.conf @@ -4,7 +4,7 @@ # plan_file = sql/sqitch.plan [engine "pg"] - target = db:pg:emojied_db + target = db:pg:emojied_development # registry = sqitch # client = psql [deploy]