diff --git a/.github/workflows/update-flake.yml b/.github/workflows/update-flake.yml index 3033d148..6194dc1b 100644 --- a/.github/workflows/update-flake.yml +++ b/.github/workflows/update-flake.yml @@ -41,22 +41,40 @@ jobs: email "$id+$name@users.noreply.github.com" \ >>"$GITHUB_OUTPUT" - - uses: DeterminateSystems/update-flake-lock@v26 - with: - token: ${{ steps.generate-token.outputs.token }} - git-committer-name: ${{ steps.user-info.outputs.name }} - git-committer-email: ${{ steps.user-info.outputs.email }} - git-author-name: ${{ steps.user-info.outputs.name }} - git-author-email: ${{ steps.user-info.outputs.email }} - branch: update_flake_lock_action_${{ matrix.branch }} - commit-msg: "flake: update all inputs" - pr-title: "${{ startsWith(matrix.branch, 'release') && format('[{0}] ', matrix.branch) || '' }}stylix: update all flake inputs" # yamllint disable-line rule:line-length - pr-labels: "topic: dependencies" - pr-body: > - Automated changes by the - [update-flake-lock](https://github.com/DeterminateSystems/update-flake-lock) - GitHub Action. + - name: setup git + env: + name: ${{ steps.user-info.outputs.name }} + email: ${{ steps.user-info.outputs.email }} + run: | + git config --global user.name "$name" + git config --global user.email "$email" - ``` - {{ env.GIT_COMMIT_MESSAGE }} - ``` + - name: update lock files + run: | + nix flake update \ + --commit-lock-file \ + --option commit-lock-file-summary "flake: update root inputs" + + nix flake update \ + --commit-lock-file \ + --flake ./flake/dev \ + --option commit-lock-file-summary "flake: update dev inputs" + + - name: create pull request + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + base_branch: ${{ matrix.branch }} + pr_branch: update_flake_lock_action_${{ matrix.branch }} + title: "${{ startsWith(matrix.branch, 'release') && format('[{0}] ', matrix.branch) || '' }}flake: update public and dev inputs" # yamllint disable-line rule:line-length + run: | + git switch --create "$pr_branch" + + git push origin "$pr_branch" \ + --force \ + --set-upstream + + gh pr create \ + --base "$base_branch" \ + --title "$title" \ + --label "topic: dependencies" || + echo "Failed to create PR" diff --git a/default.nix b/default.nix index 4e4468ed..675809c0 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,7 @@ (import ( let inherit (lock.nodes.flake-compat.locked) narHash rev; - lock = builtins.fromJSON (builtins.readFile ./flake.lock); + lock = builtins.fromJSON (builtins.readFile ./flake/dev/flake.lock); in fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz"; diff --git a/flake.lock b/flake.lock index da2edfa1..957bf864 100644 --- a/flake.lock +++ b/flake.lock @@ -83,21 +83,6 @@ "type": "github" } }, - "flake-compat": { - "locked": { - "lastModified": 1747046372, - "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -134,51 +119,6 @@ "type": "github" } }, - "git-hooks": { - "inputs": { - "flake-compat": [ - "flake-compat" - ], - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1747372754, - "narHash": "sha256-2Y53NGIX2vxfie1rOW0Qb86vjRZ7ngizoo+bnXU9D9k=", - "owner": "cachix", - "repo": "git-hooks.nix", - "rev": "80479b6ec16fefd9c1db3ea13aeb038c60530f46", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "git-hooks.nix", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "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" - } - }, "gnome-shell": { "flake": false, "locked": { @@ -196,26 +136,6 @@ "type": "github" } }, - "home-manager": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1751146119, - "narHash": "sha256-gvjG95TCnUVJkvQvLMlnC4NqiqFyBdJk3o8/RwuHeaU=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "76d0c31fce2aa0c71409de953e2f9113acd5b656", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "home-manager", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1748460289, @@ -263,11 +183,8 @@ "base16-helix": "base16-helix", "base16-vim": "base16-vim", "firefox-gnome-theme": "firefox-gnome-theme", - "flake-compat": "flake-compat", "flake-parts": "flake-parts", - "git-hooks": "git-hooks", "gnome-shell": "gnome-shell", - "home-manager": "home-manager", "nixpkgs": "nixpkgs", "nur": "nur", "systems": "systems", diff --git a/flake.nix b/flake.nix index 684dae85..84163b95 100644 --- a/flake.nix +++ b/flake.nix @@ -41,16 +41,6 @@ flake = false; }; - flake-compat.url = "github:edolstra/flake-compat"; - - git-hooks = { - url = "github:cachix/git-hooks.nix"; - inputs = { - flake-compat.follows = "flake-compat"; - nixpkgs.follows = "nixpkgs"; - }; - }; - gnome-shell = { # TODO: Unlocking the input and pointing to official repository requires # updating the patch: @@ -59,12 +49,6 @@ flake = false; }; - # The 'home-manager' input is used to generate the documentation. - home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - nur = { url = "github:nix-community/NUR"; inputs = { diff --git a/flake/default.nix b/flake/default.nix index eaef7b99..5fb20f75 100644 --- a/flake/default.nix +++ b/flake/default.nix @@ -1,86 +1,21 @@ +{ inputs, lib, ... }: { imports = [ + inputs.flake-parts.flakeModules.partitions ./deprecation - ./dev-shell.nix ./modules.nix ./packages.nix - ./pre-commit.nix + ./propagated-packages.nix ]; - perSystem = - { pkgs, ... }: - { - # TODO: consider using https://flake.parts/options/treefmt-nix.html once - # dev flake is partitioned - formatter = pkgs.treefmt.withConfig { - runtimeInputs = with pkgs; [ - # keep-sorted start - biome - keep-sorted - nixfmt-rfc-style - ruff - stylish-haskell - # keep-sorted end - ]; + partitions.dev = { + module = ./dev; + extraInputsFlake = ./dev; + }; - settings = { - on-unmatched = "info"; - tree-root-file = "flake.nix"; - - formatter = { - # keep-sorted start block=yes - biome = { - command = "biome"; - options = [ - "format" - "--write" - "--no-errors-on-unmatched" - "--config-path" - (pkgs.writers.writeJSON "biome.json" { - formatter = { - indentStyle = "space"; - indentWidth = 2; - lineWidth = 80; - }; - }) - ]; - includes = [ - "*.css" - "*.js" - "*.json" - ]; - excludes = [ - # Contains custom syntax that biome can't handle - "modules/swaync/base.css" - ]; - }; - keep-sorted = { - command = "keep-sorted"; - includes = [ "*" ]; - }; - nixfmt = { - command = "nixfmt"; - options = [ "--width=80" ]; - includes = [ "*.nix" ]; - }; - ruff = { - command = "ruff"; - options = [ - "--config" - (pkgs.writers.writeTOML "ruff.toml" { - line-length = 80; - }) - "format" - ]; - includes = [ "*.py" ]; - }; - stylish-haskell = { - command = "stylish-haskell"; - includes = [ "*.hx" ]; - }; - # keep-sorted end - }; - }; - }; - }; + partitionedAttrs = lib.genAttrs [ + "checks" + "devShells" + "formatter" + ] (_: "dev"); } diff --git a/flake/dev/default.nix b/flake/dev/default.nix new file mode 100644 index 00000000..4cc3d37c --- /dev/null +++ b/flake/dev/default.nix @@ -0,0 +1,84 @@ +{ + imports = [ + ./dev-shell.nix + ./nixpkgs-and-dev-nixpkgs-version-consistency.nix + ./packages.nix + ./pre-commit.nix + ]; + + perSystem = + { pkgs, ... }: + { + # TODO: consider using https://flake.parts/options/treefmt-nix.html + formatter = pkgs.treefmt.withConfig { + runtimeInputs = with pkgs; [ + # keep-sorted start + biome + keep-sorted + nixfmt-rfc-style + ruff + stylish-haskell + # keep-sorted end + ]; + + settings = { + on-unmatched = "info"; + tree-root-file = "flake.nix"; + + formatter = { + # keep-sorted start block=yes + biome = { + command = "biome"; + options = [ + "format" + "--write" + "--no-errors-on-unmatched" + "--config-path" + (pkgs.writers.writeJSON "biome.json" { + formatter = { + indentStyle = "space"; + indentWidth = 2; + lineWidth = 80; + }; + }) + ]; + includes = [ + "*.css" + "*.js" + "*.json" + ]; + excludes = [ + # Contains custom syntax that biome can't handle + "modules/swaync/base.css" + ]; + }; + keep-sorted = { + command = "keep-sorted"; + includes = [ "*" ]; + }; + nixfmt = { + command = "nixfmt"; + options = [ "--width=80" ]; + includes = [ "*.nix" ]; + }; + ruff = { + command = "ruff"; + options = [ + "--config" + (pkgs.writers.writeTOML "ruff.toml" { + line-length = 80; + }) + "format" + ]; + includes = [ "*.py" ]; + }; + stylish-haskell = { + command = "stylish-haskell"; + includes = [ "*.hx" ]; + }; + # keep-sorted end + }; + }; + }; + }; +} diff --git a/flake/dev-shell.nix b/flake/dev/dev-shell.nix similarity index 100% rename from flake/dev-shell.nix rename to flake/dev/dev-shell.nix diff --git a/flake/dev/flake.lock b/flake/dev/flake.lock new file mode 100644 index 00000000..64f1d79d --- /dev/null +++ b/flake/dev/flake.lock @@ -0,0 +1,110 @@ +{ + "nodes": { + "dev-nixpkgs": { + "locked": { + "lastModified": 1748460289, + "narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1747046372, + "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "dev-nixpkgs" + ] + }, + "locked": { + "lastModified": 1747372754, + "narHash": "sha256-2Y53NGIX2vxfie1rOW0Qb86vjRZ7ngizoo+bnXU9D9k=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "80479b6ec16fefd9c1db3ea13aeb038c60530f46", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "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" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "dev-nixpkgs" + ] + }, + "locked": { + "lastModified": 1751146119, + "narHash": "sha256-gvjG95TCnUVJkvQvLMlnC4NqiqFyBdJk3o8/RwuHeaU=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "76d0c31fce2aa0c71409de953e2f9113acd5b656", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "root": { + "inputs": { + "dev-nixpkgs": "dev-nixpkgs", + "flake-compat": "flake-compat", + "git-hooks": "git-hooks", + "home-manager": "home-manager" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake/dev/flake.nix b/flake/dev/flake.nix new file mode 100644 index 00000000..214a83e0 --- /dev/null +++ b/flake/dev/flake.nix @@ -0,0 +1,54 @@ +{ + description = '' + Private inputs for development purposes. These are used by the top level + flake in the `dev` partition, but do not appear in consumers' lock files. + ''; + + inputs = { + # We need to define a nixpkgs input so that other inputs can follow it. + # It is prefixed with 'dev-' to avoid shadowing the public flake's + # 'nixpkgs' input, which could affect local testing with --override-input. + # + # TODO: Replace + # + # dev-nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + # + # with + # + # dev-nixpkgs = { + # url = "path:../.."; + # inputs = { + # "".follows = ""; + # "".follows = ""; + # "".follows = ""; + # }; + # }; + # + # once 26.05 is released, giving non-flake end-users and Stylix + # contributors two LTS releases to adopt Nix 2.26+ [1]. Note that + # non-nixpkgs public flake inputs should be disabled. + # + # [1]: https://github.com/NixOS/nix/blob/d4f67fd46dfe2bc950bdfa14273f87b8a4c32e47/doc/manual/source/release-notes/rl-2.26.md?plain=1#L3-L11 + dev-nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + # keep-sorted start block=yes newline_separated=yes + flake-compat.url = "github:edolstra/flake-compat"; + + git-hooks = { + url = "github:cachix/git-hooks.nix"; + inputs = { + flake-compat.follows = "flake-compat"; + nixpkgs.follows = "dev-nixpkgs"; + }; + }; + + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "dev-nixpkgs"; + }; + # keep-sorted end + }; + + # This flake is only used for its inputs. + outputs = _: { }; +} diff --git a/flake/dev/nixpkgs-and-dev-nixpkgs-version-consistency.nix b/flake/dev/nixpkgs-and-dev-nixpkgs-version-consistency.nix new file mode 100644 index 00000000..56e373be --- /dev/null +++ b/flake/dev/nixpkgs-and-dev-nixpkgs-version-consistency.nix @@ -0,0 +1,24 @@ +{ inputs, ... }: +{ + perSystem = + { pkgs, ... }: + { + checks.nixpkgs-and-dev-nixpkgs-version-consistency = + pkgs.runCommand "nixpkgs-and-dev-nixpkgs-version-consistency" + { + dev_nixpkgs = inputs.dev-nixpkgs.narHash; + nixpkgs = inputs.nixpkgs.narHash; + } + '' + if [ "$nixpkgs" != "$dev_nixpkgs" ]; then + printf \ + 'inconsistent nixpkgs (%s) and dev-nixpkgs (%s) versions\n' \ + "$nixpkgs" \ + "$dev_nixpkgs" \ + >&2 + exit 1 + fi + mkdir "$out" + ''; + }; +} diff --git a/flake/dev/packages.nix b/flake/dev/packages.nix new file mode 100644 index 00000000..bb8aa9b1 --- /dev/null +++ b/flake/dev/packages.nix @@ -0,0 +1,18 @@ +{ lib, inputs, ... }: +{ + perSystem = + { pkgs, config, ... }: + { + # Build all packages with 'nix flake check' instead of only verifying they + # are derivations. + checks = config.packages; + + # Testbeds are virtual machines based on NixOS, therefore they are + # only available for Linux systems. + packages = lib.mkIf pkgs.stdenv.hostPlatform.isLinux ( + import ../../stylix/testbed/default.nix { + inherit pkgs inputs lib; + } + ); + }; +} diff --git a/flake/pre-commit.nix b/flake/dev/pre-commit.nix similarity index 100% rename from flake/pre-commit.nix rename to flake/dev/pre-commit.nix diff --git a/flake/packages.nix b/flake/packages.nix index 23005774..88648577 100644 --- a/flake/packages.nix +++ b/flake/packages.nix @@ -1,33 +1,19 @@ -{ lib, inputs, ... }: +{ inputs, ... }: { - perSystem = { pkgs, config, ... }: { - # Build all packages with 'nix flake check' instead of only verifying they - # are derivations. - checks = config.packages; - # Make 'nix run .#doc' serve the documentation site apps.doc.program = config.packages.serve-docs; - packages = lib.mkMerge [ - # Testbeds are virtual machines based on NixOS, therefore they are - # only available for Linux systems. - (lib.mkIf pkgs.stdenv.hostPlatform.isLinux ( - import ../stylix/testbed { - inherit pkgs inputs lib; - } - )) - { - doc = pkgs.callPackage ../doc { - inherit (inputs) self; - }; - serve-docs = pkgs.callPackage ../doc/server.nix { - inherit (config.packages) doc; - }; - palette-generator = pkgs.callPackage ../palette-generator { }; - } - ]; + packages = { + doc = pkgs.callPackage ../doc { + inherit (inputs) self; + }; + serve-docs = pkgs.callPackage ../doc/server.nix { + inherit (config.packages) doc; + }; + palette-generator = pkgs.callPackage ../palette-generator { }; + }; }; } diff --git a/flake/propagated-packages.nix b/flake/propagated-packages.nix new file mode 100644 index 00000000..4198c8d5 --- /dev/null +++ b/flake/propagated-packages.nix @@ -0,0 +1,24 @@ +{ + lib, + config, + partitionStack, + ... +}: +{ + # For any output attrs normally defined by the public flake configuration, + # any exceptions must be manually propagated from the `dev` partition. + # + # NOTE: Attrs should be explicitly propagated at the deepest level. + # Otherwise the partition won't be lazy, making it pointless. + # E.g. propagate `packages.${system}.foo` instead of `packages.${system}` + # See: https://github.com/hercules-ci/flake-parts/issues/258 + perSystem = + { pkgs, system, ... }: + lib.optionalAttrs (partitionStack == [ ]) { + packages = lib.mkIf pkgs.stdenv.hostPlatform.isLinux ( + lib.mapAttrs ( + name: _: config.partitions.dev.module.flake.packages.${system}.${name} + ) (import ../stylix/testbed/autoload.nix { inherit lib pkgs; }) + ); + }; +}