From 9e49dfd96cd7c62ddeff9bd202e6c5f0a717f2b5 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Sun, 8 Nov 2026 15:48:42 +0100 Subject: [PATCH] Separate out a dev flake This makes the main flake more lean and doesn't pollute downstream consumers as much. --- .envrc | 4 ++ .github/workflows/attic.yml | 4 +- .github/workflows/ci.yml | 16 +++--- .github/workflows/dependencies.yml | 2 +- default.nix | 55 +++++++++++++++++--- dev/flake.lock | 83 ++++++++++++++++++++++++++++++ dev/flake.nix | 44 ++++++++++++++++ shell.nix => dev/shell.nix | 24 ++++----- flake.lock | 48 ++--------------- flake.nix | 58 +++++---------------- 10 files changed, 216 insertions(+), 122 deletions(-) create mode 100644 .envrc create mode 100644 dev/flake.lock create mode 100644 dev/flake.nix rename shell.nix => dev/shell.nix (85%) diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..6b0ff558 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +watch_file flake.lock +watch_file flake.nix +watch_file gemset.nix +use_flake ./dev diff --git a/.github/workflows/attic.yml b/.github/workflows/attic.yml index a029675b..17cc4c36 100644 --- a/.github/workflows/attic.yml +++ b/.github/workflows/attic.yml @@ -43,5 +43,5 @@ jobs: endpoint: https://attic.chvp.be cache: accentor token: '${{ secrets.ATTIC_AUTH_TOKEN }}' - - run: nix build -L --no-link .#devShells.$(nix eval --impure --expr "builtins.currentSystem").accentor-api - - run: nix build -L --no-link .#devShells.$(nix eval --impure --expr "builtins.currentSystem").deps + - run: nix build -L --no-link ./dev#devShells.$(nix eval --impure --expr "builtins.currentSystem").accentor-api + - run: nix build -L --no-link ./dev#devShells.$(nix eval --impure --expr "builtins.currentSystem").deps diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 528ebfab..f9db644a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,12 +30,12 @@ jobs: token: '${{ secrets.ATTIC_AUTH_TOKEN }}' - name: "Setup database" run: | - nix develop --command pg:start - nix develop --command rails db:setup + nix develop ./dev --command pg:start + nix develop ./dev --command rails db:setup - name: Run tests env: CI: true - run: nix develop --command rails test + run: nix develop ./dev --command rails test - uses: codecov/codecov-action@v7 with: token: ${{ secrets.CODECOV_TOKEN }} # required @@ -58,9 +58,9 @@ jobs: - name: Lint with rubocop env: RAILS_ENV: "test" - run: nix develop --command rubocop -c .rubocop.yml -f github + run: nix develop ./dev --command rubocop -c .rubocop.yml -f github - name: Scan with brakeman - run: nix develop --command brakeman --no-pager + run: nix develop ./dev --command brakeman --no-pager annotate-diff-check: runs-on: ubuntu-latest steps: @@ -79,10 +79,10 @@ jobs: token: '${{ secrets.ATTIC_AUTH_TOKEN }}' - name: "Setup database" run: | - nix develop --command pg:start - nix develop --command rails db:setup + nix develop ./dev --command pg:start + nix develop ./dev --command rails db:setup - name: Run annotate - run: nix develop --command annotaterb models + run: nix develop ./dev --command annotaterb models - name: Check diff run: | if ! git diff-index --quiet HEAD; then diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index ef738eea..2cddb751 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -28,7 +28,7 @@ jobs: cache: accentor token: '${{ secrets.ATTIC_AUTH_TOKEN }}' - name: Run bundix - run: nix develop .#deps --command bundix + run: nix develop ./dev#deps --command bundix - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v7.2.1 with: diff --git a/default.nix b/default.nix index 0e080b5e..86cb79b5 100644 --- a/default.nix +++ b/default.nix @@ -1,20 +1,56 @@ -{ stdenv -, lib -, accentor-api-env +{ + stdenv, + lib, + ruby_4_0, + bundlerEnv, }: let - rootFiles = lib.fileset.fileFilter (file: builtins.elem file.name [ "config.ru" "Gemfile" "Gemfile.lock" "gemset.nix" "Rakefile" ]) ./.; - srcFiles = lib.fileset.unions [ rootFiles ./app ./bin ./config ./db ./lib ./public ]; + rootFiles = lib.fileset.fileFilter ( + file: + builtins.elem file.name [ + "config.ru" + "Gemfile" + "Gemfile.lock" + "gemset.nix" + "Rakefile" + ] + ) ./.; + srcFiles = lib.fileset.unions [ + rootFiles + ./app + ./bin + ./config + ./db + ./lib + ./public + ]; + ruby = ruby_4_0.override { jemallocSupport = true; }; + gems = bundlerEnv { + inherit ruby; + name = "accentor-api-env"; + gemfile = ./Gemfile; + lockfile = ./Gemfile.lock; + gemset = ./gemset.nix; + groups = [ + "default" + "development" + "test" + "production" + ]; + }; in stdenv.mkDerivation { pname = "accentor-api"; version = "0.24.0"; - src = lib.fileset.toSource { root = ./.; fileset = srcFiles; }; + src = lib.fileset.toSource { + root = ./.; + fileset = srcFiles; + }; buildPhase = '' # Compile bootsnap cache - ${accentor-api-env}/bin/bundle exec bootsnap precompile --gemfile app/ lib/ + ${gems}/bin/bundle exec bootsnap precompile --gemfile app/ lib/ ''; installPhase = '' @@ -22,5 +58,8 @@ stdenv.mkDerivation { cp -r * $out ''; - passthru.env = accentor-api-env; + passthru = { + inherit ruby; + env = gems; + }; } diff --git a/dev/flake.lock b/dev/flake.lock new file mode 100644 index 00000000..5faa3203 --- /dev/null +++ b/dev/flake.lock @@ -0,0 +1,83 @@ +{ + "nodes": { + "bundix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1762235257, + "narHash": "sha256-QyXFgaXQETr9BmwUbWM/2EtF+my6Arpt71xItZy3NL8=", + "owner": "inscapist", + "repo": "bundix", + "rev": "2233b24084316b4de1d55321483554f457a09cfc", + "type": "github" + }, + "original": { + "owner": "inscapist", + "repo": "bundix", + "type": "github" + } + }, + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1791918082, + "narHash": "sha256-oN9JrhRfHa7MUTdUq+11dHn7u0Z4WfEA4mhzBq0/zoQ=", + "owner": "numtide", + "repo": "devshell", + "rev": "9e29c63dde99a2d80c94b3d024c9768c01544558", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1794042290, + "narHash": "sha256-VZ8WvA9m3XN36juXyg/GwbDRU2OezOHJlXpJCXkccv0=", + "rev": "f4a03c008967841f2a0b3cb7c436fc6fc31671f6", + "type": "tarball", + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1113206.f4a03c008967/nixexprs.tar.zst" + }, + "original": { + "type": "tarball", + "url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst" + } + }, + "root": { + "inputs": { + "bundix": "bundix", + "devshell": "devshell", + "nixpkgs": "nixpkgs", + "super": "super" + } + }, + "super": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "path": "../", + "type": "path" + }, + "original": { + "path": "../", + "type": "path" + }, + "parent": [] + } + }, + "root": "root", + "version": 7 +} diff --git a/dev/flake.nix b/dev/flake.nix new file mode 100644 index 00000000..b411712a --- /dev/null +++ b/dev/flake.nix @@ -0,0 +1,44 @@ +{ + description = "Accentor API development"; + + inputs = { + super = { + url = "../"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst"; + bundix = { + url = "github:inscapist/bundix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + devshell = { + url = "github:numtide/devshell"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs: { + devShells = builtins.mapAttrs ( + system: pkgs': + let + pkgs = pkgs'.appendOverlays [ + (self: super: { + bundix = inputs.bundix; + }) + inputs.super.overlays.default + inputs.devshell.overlays.default + ]; + in + { + accentor-api = pkgs.callPackage ./shell.nix { }; + default = inputs.self.devShells.${system}.accentor-api; + deps = pkgs.devshell.mkShell { + packages = [ + pkgs.accentor-api.ruby + pkgs.bundix + ]; + }; + } + ) inputs.nixpkgs.legacyPackages; + }; +} diff --git a/shell.nix b/dev/shell.nix similarity index 85% rename from shell.nix rename to dev/shell.nix index 231c9b03..6bb4d49f 100644 --- a/shell.nix +++ b/dev/shell.nix @@ -1,22 +1,22 @@ -{ devshell -, lib -, accentor-api-env -, ffmpeg -, nixpkgs-fmt -, postgresql_18 -, bundix +{ + devshell, + lib, + accentor-api, + ffmpeg, + nixfmt, + postgresql_18, }: let - ruby = accentor-api-env.wrappedRuby; + ruby = accentor-api.env.wrappedRuby; in devshell.mkShell { name = "Accentor API"; packages = [ - accentor-api-env + accentor-api.env (lib.lowPrio ruby) ffmpeg - nixpkgs-fmt + nixfmt postgresql_18 ]; env = [ @@ -71,8 +71,8 @@ devshell.mkShell { category = "dependencies"; help = "Update the `Gemfile.lock` and `gemset.nix` files"; command = '' - ${ruby}/bin/bundle lock --add-checksums - ${bundix}/bin/bundix + nix develop $PRJ_ROOT/dev#deps -c bundle lock --add-checksums + nix develop $PRJ_ROOT/dev#deps -c bundix ''; } ]; diff --git a/flake.lock b/flake.lock index 12f210cf..3e5fd251 100644 --- a/flake.lock +++ b/flake.lock @@ -1,52 +1,12 @@ { "nodes": { - "bundix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1762235257, - "narHash": "sha256-QyXFgaXQETr9BmwUbWM/2EtF+my6Arpt71xItZy3NL8=", - "owner": "inscapist", - "repo": "bundix", - "rev": "2233b24084316b4de1d55321483554f457a09cfc", - "type": "github" - }, - "original": { - "owner": "inscapist", - "repo": "bundix", - "type": "github" - } - }, - "devshell": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1791918082, - "narHash": "sha256-oN9JrhRfHa7MUTdUq+11dHn7u0Z4WfEA4mhzBq0/zoQ=", - "owner": "numtide", - "repo": "devshell", - "rev": "9e29c63dde99a2d80c94b3d024c9768c01544558", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1793540411, - "narHash": "sha256-fiPJ88izTVucjeo2EQ3jk4aWmLg03I1D4vxnX2QjEgE=", + "lastModified": 1794042290, + "narHash": "sha256-ziZn2PvCJE5JEEpqTdxXwJpPB+L3YqoCpTAMCzyaP3U=", "owner": "nixos", "repo": "nixpkgs", - "rev": "0bb2eedc20e4739f29e8045034f2828ad7054f8f", + "rev": "f4a03c008967841f2a0b3cb7c436fc6fc31671f6", "type": "github" }, "original": { @@ -58,8 +18,6 @@ }, "root": { "inputs": { - "bundix": "bundix", - "devshell": "devshell", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index a4572371..eb0c1c80 100644 --- a/flake.nix +++ b/flake.nix @@ -1,51 +1,17 @@ { description = "Accentor API"; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - bundix = { - url = "github:inscapist/bundix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - devshell = { - url = "github:numtide/devshell"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - outputs = inputs: - let - rubyForPkgs = pkgs: pkgs.ruby_4_0.override { jemallocSupport = true; }; - gemsForPkgs = pkgs: pkgs.bundlerEnv { - name = "accentor-api-env"; - ruby = rubyForPkgs pkgs; - gemfile = ./Gemfile; - lockfile = ./Gemfile.lock; - gemset = ./gemset.nix; - groups = [ "default" "development" "test" "production" ]; - }; - in - { - packages = builtins.mapAttrs - (system: pkgs': - let - pkgs = pkgs'.extend (self: super: { bundix = inputs.bundix; }); - in - { - accentor-api = pkgs.callPackage ./default.nix { accentor-api-env = gemsForPkgs pkgs; }; - default = inputs.self.packages.${system}.accentor-api; - }) - inputs.nixpkgs.legacyPackages; - devShells = builtins.mapAttrs - (system: pkgs': - let - pkgs = pkgs'.appendOverlays [ (self: super: { bundix = inputs.bundix; }) inputs.devshell.overlays.default ]; - in - { - accentor-api = pkgs.callPackage ./shell.nix { accentor-api-env = gemsForPkgs pkgs; }; - default = inputs.self.devShells.${system}.accentor-api; - deps = pkgs.devshell.mkShell { packages = [ (rubyForPkgs pkgs) pkgs.bundix ]; }; - }) - inputs.nixpkgs.legacyPackages; - }; + outputs = inputs: { + packages = builtins.mapAttrs (system: pkgs: { + accentor-api = pkgs.callPackage ./default.nix { }; + default = inputs.self.packages.${system}.accentor-api; + }) inputs.nixpkgs.legacyPackages; + overlays.default = ( + self: super: { + accentor-api = self.callPackage ./default.nix { }; + } + ); + }; }