diff --git a/.envrc b/.envrc index 6c1ab2af..7c75ab2b 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake ./tools/nix +use flake ./tools/nix --no-pure-eval diff --git a/.gitignore b/.gitignore index 3befbb3f..f1b1ea8b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,9 @@ __pycache__/ *.py[cod] *$py.class -# Direnv cache +# Direnv/Devenv cache .direnv +.devenv # Distribution / packaging diff --git a/justfile b/justfile index ab9a5482..3e4416f0 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,8 @@ set positional-arguments set dotenv-load set shell := ["bash", "-cue"] +root_dir := `git rev-parse --show-toplevel` +flake_dir := root_dir / "tools/nix" # Manage container images. mod image 'tools/just/image.just' @@ -21,6 +23,11 @@ get-version: | tr -d '"' +alias dev := develop +# Enter a development shell. +develop: + just nix-develop default + # Set up python environment. setup: @echo "🔧 Setting up python environment" @@ -65,3 +72,19 @@ deploy: # Generate changelog changelog *args: @git-cliff -l -c pyproject.toml {{args}} + +## Nix Stuff ================================================================== +# Show all packages configured in the Nix `flake.nix`. +nix-list *args: + cd tools/nix && nix flake --no-pure-eval show + +# Enter the Nix `devShell` with name `$1` and execute the command `${@:2}` (default command is '$SHELL') +[private] +nix-develop *args: + #!/usr/bin/env bash + set -eu + shell="$1"; shift 1; + args=("$@") && [ "${#args[@]}" != 0 ] || args="$SHELL" + nix develop --no-pure-eval --accept-flake-config \ + "{{flake_dir}}#$shell" --command "${args[@]}" +## ============================================================================ diff --git a/tools/nix/flake.lock b/tools/nix/flake.lock index 4e2eb505..d3f33856 100644 --- a/tools/nix/flake.lock +++ b/tools/nix/flake.lock @@ -1,5 +1,96 @@ { "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "devenv" + ], + "flake-compat": [ + "devenv" + ], + "git-hooks": [ + "devenv" + ], + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1742042642, + "narHash": "sha256-D0gP8srrX0qj+wNYNPdtVJsQuFzIng3q43thnHXQ/es=", + "owner": "cachix", + "repo": "cachix", + "rev": "a624d3eaf4b1d225f918de8543ed739f2f574203", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat", + "git-hooks": "git-hooks", + "nix": "nix", + "nixpkgs": [ + "nixpkgsDevenv" + ] + }, + "locked": { + "lastModified": 1746034422, + "narHash": "sha256-CEVWxRaln3sp0541QpMfcfmI2w+RN72UgNLV5Dy9sco=", + "owner": "cachix", + "repo": "devenv", + "rev": "f19b62ea677ec6046d78243e176fa01d5ef0d55a", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,43 +109,172 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1742649964, + "narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "libgit2": { + "flake": false, + "locked": { + "lastModified": 1697646580, + "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", + "owner": "libgit2", + "repo": "libgit2", + "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", + "type": "github" + }, + "original": { + "owner": "libgit2", + "repo": "libgit2", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "flake-parts": "flake-parts", + "libgit2": "libgit2", + "nixpkgs": "nixpkgs_2", + "nixpkgs-23-11": [ + "devenv" + ], + "nixpkgs-regression": [ + "devenv" + ], + "pre-commit-hooks": [ + "devenv" + ] + }, + "locked": { + "lastModified": 1745930071, + "narHash": "sha256-bYyjarS3qSNqxfgc89IoVz8cAFDkF9yPE63EJr+h50s=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b455edf3505f1bf0172b39a735caef94687d0d9c", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.24", + "repo": "nix", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1745234285, - "narHash": "sha256-GfpyMzxwkfgRVN0cTGQSkTC0OHhEkv3Jf6Tcjm//qZ0=", - "owner": "nixos", + "lastModified": 1733212471, + "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "c11863f1e964833214b767f4a369c6e6a7aba141", + "rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", "type": "github" }, "original": { - "owner": "nixos", + "owner": "NixOS", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, - "nixpkgsStable": { + "nixpkgsDevenv": { + "locked": { + "lastModified": 1746807397, + "narHash": "sha256-zU2z0jlkJGWLhdNr/8AJSxqK8XD0IlQgHp3VZcP56Aw=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "c5208b594838ea8e6cca5997fbf784b7cca1ca90", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { - "lastModified": 1745279238, - "narHash": "sha256-AQ7M9wTa/Pa/kK5pcGTgX/DGqMHyzsyINfN7ktsI7Fo=", + "lastModified": 1717432640, + "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1745234285, + "narHash": "sha256-GfpyMzxwkfgRVN0cTGQSkTC0OHhEkv3Jf6Tcjm//qZ0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "9684b53175fc6c09581e94cc85f05ab77464c7e3", + "rev": "c11863f1e964833214b767f4a369c6e6a7aba141", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-24.11", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { + "devenv": "devenv", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "nixpkgsStable": "nixpkgsStable" + "nixpkgs": "nixpkgs_3", + "nixpkgsDevenv": "nixpkgsDevenv" } }, "systems": { diff --git a/tools/nix/flake.nix b/tools/nix/flake.nix index 99960e52..4cc454c5 100644 --- a/tools/nix/flake.nix +++ b/tools/nix/flake.nix @@ -4,53 +4,58 @@ inputs = { # Nixpkgs nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - - # You can access packages and modules from different nixpkgs revs - # at the same time. Here's an working example: - nixpkgsStable.url = "github:nixos/nixpkgs/nixos-24.11"; - # Also see the 'stable-packages' overlay at 'overlays/default.nix'. - flake-utils.url = "github:numtide/flake-utils"; + + # The devenv module to create good development shells. + devenv = { + url = "github:cachix/devenv/latest"; + inputs.nixpkgs.follows = "nixpkgsDevenv"; + }; + # We should lock the pkgs in `mkShell` here: + # https://github.com/cachix/devenv/issues/1797 + # to devenvs rolling nixpkgs. Note: that does not restrict the use of + # 'nixpkgs' input in devenv modules. + nixpkgsDevenv.url = "github:cachix/devenv-nixpkgs/rolling"; }; - outputs = { - nixpkgs, - flake-utils, - ... - }: - flake-utils.lib.eachDefaultSystem - # Creates an attribute map `{ devShells..default = ...}` - # by calling this function: - ( - system: let - # Import nixpkgs and load it into pkgs. - pkgs = import nixpkgs { - inherit system; - }; + outputs = + inputs: + inputs.flake-utils.lib.eachDefaultSystem + # Creates an attribute map `{ devShells..default = ...}` + # by calling this function: + ( + system: + let + # Import nixpkgs and load it into pkgs. + pkgs = import inputs.nixpkgs { + inherit system; + }; - # Things needed at build-time. - packagesBasic = with pkgs; [ - bash - coreutils - curl - findutils - git - git-cliff - just - pyright - uv - zsh - ]; + # Things needed at build-time. + packages = with pkgs; [ + bash + coreutils + curl + findutils + git + git-cliff + just + pyright + uv + zsh + ]; + in + { + devShells = { + default = inputs.devenv.lib.mkShell { + inherit inputs; + pkgs = inputs.nixpkgsDevenv.legacyPackages.${system}; - # Things needed at runtime. - buildInputs = []; - in { - devShells = { - default = pkgs.mkShell { - inherit buildInputs; - nativeBuildInputs = packagesBasic; + modules = [ + { inherit packages; } + ]; + }; }; - }; - } - ); + } + ); }