diff --git a/.github/workflows/update-flake.yml b/.github/workflows/update-flake.yml index 9edfceba..b0c170eb 100644 --- a/.github/workflows/update-flake.yml +++ b/.github/workflows/update-flake.yml @@ -31,7 +31,7 @@ jobs: with: token: ${{ steps.generate-token.outputs.token }} branch: update_flake_lock_action_${{ matrix.branch }} - commit-msg: "stylix: update all flake inputs" + 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: dependencies # yamllint disable rule:line-length diff --git a/docs/src/commit_convention.md b/docs/src/commit_convention.md index ae7187f5..09136968 100644 --- a/docs/src/commit_convention.md +++ b/docs/src/commit_convention.md @@ -11,13 +11,14 @@ To keep things consistent, commit messages should follow a format Where the scope is one of: -| Scope | Purpose | -|----------------|------------------------------------------------------------------------| -| `ci` | Changes to GitHub Actions workflows. | -| `doc` | Changes to the website, `README.md`, and so on. | -| `stylix` | Changes in the `stylix` directory, `flake.nix`, and other global code. | -| Name of target | Changes to code for a particular target. | -| `treewide` | Changes across many targets. | +| Scope | Purpose | +|----------------|------------------------------------------------------------------| +| `ci` | Changes to GitHub Actions workflows. | +| `doc` | Changes to the website, `README.md`, and so on. | +| `flake` | Changes in the `flake` directory, `flake.nix`, and `flake.lock`. | +| `stylix` | Changes in the `stylix` directory and other global code. | +| Name of target | Changes to code for a particular target. | +| `treewide` | Changes across many targets. | The scope is meant to indicate which area of the code was changed. Specifying the type of change, such as `feat` or `fix`, is not necessary. Dependency diff --git a/flake.lock b/flake.lock index 1ca516fc..0b84a71d 100644 --- a/flake.lock +++ b/flake.lock @@ -101,7 +101,6 @@ "flake-parts": { "inputs": { "nixpkgs-lib": [ - "nur", "nixpkgs" ] }, @@ -119,26 +118,6 @@ "type": "github" } }, - "flake-utils": { - "inputs": { - "systems": [ - "systems" - ] - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "fromYaml": { "flake": false, "locked": { @@ -255,7 +234,9 @@ }, "nur": { "inputs": { - "flake-parts": "flake-parts", + "flake-parts": [ + "flake-parts" + ], "nixpkgs": [ "nixpkgs" ], @@ -283,7 +264,7 @@ "base16-vim": "base16-vim", "firefox-gnome-theme": "firefox-gnome-theme", "flake-compat": "flake-compat", - "flake-utils": "flake-utils", + "flake-parts": "flake-parts", "git-hooks": "git-hooks", "gnome-shell": "gnome-shell", "home-manager": "home-manager", diff --git a/flake.nix b/flake.nix index dfc5a16e..d493f892 100644 --- a/flake.nix +++ b/flake.nix @@ -4,9 +4,9 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-utils = { - url = "github:numtide/flake-utils"; - inputs.systems.follows = "systems"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; }; systems.url = "github:nix-systems/default"; @@ -67,7 +67,10 @@ nur = { url = "github:nix-community/NUR"; - inputs.nixpkgs.follows = "nixpkgs"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-parts.follows = "flake-parts"; + }; }; tinted-foot = { @@ -112,211 +115,10 @@ }; outputs = - { - nixpkgs, - base16, - self, - ... - }@inputs: - inputs.flake-utils.lib.eachDefaultSystem ( - system: - let - inherit (nixpkgs) lib; - pkgs = nixpkgs.legacyPackages.${system}; - in - { - checks = lib.attrsets.unionOfDisjoint { - git-hooks = inputs.git-hooks.lib.${system}.run { - hooks = { - deadnix.enable = true; - editorconfig-checker.enable = true; - hlint.enable = true; + { flake-parts, systems, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ ./flake ]; - treefmt = { - enable = true; - package = self.formatter.${system}; - }; - - statix.enable = true; - typos = { - enable = true; - settings.configuration = '' - [default.extend-identifiers] - MrSom3body="MrSom3body" - ''; - }; - yamllint.enable = true; - }; - - src = ./.; - }; - } self.packages.${system}; - - devShells = { - default = - let - check = pkgs.writeShellApplication { - name = "stylix-check"; - runtimeInputs = with pkgs; [ - nix - nix-fast-build - ]; - text = '' - cores="$(nproc)" - system="$(nix eval --expr builtins.currentSystem --impure --raw)" - nix-fast-build \ - --eval-max-memory-size 512 \ - --eval-workers "$cores" \ - --flake ".#checks.$system" \ - --no-link \ - --skip-cached \ - "$@" - ''; - }; - in - pkgs.mkShell { - inherit (self.checks.${system}.git-hooks) shellHook; - - packages = [ - check - inputs.home-manager.packages.${system}.default - self.checks.${system}.git-hooks.enabledPackages - self.formatter.${system} - ] ++ self.formatter.${system}.runtimeInputs; - }; - - ghc = pkgs.mkShell { - inputsFrom = [ self.devShells.${system}.default ]; - packages = [ pkgs.ghc ]; - }; - }; - - formatter = pkgs.treefmt.withConfig { - runtimeInputs = with pkgs; [ - nixfmt-rfc-style - stylish-haskell - keep-sorted - ]; - - settings = { - on-unmatched = "info"; - tree-root-file = "flake.nix"; - - formatter = { - stylish-haskell = { - command = "stylish-haskell"; - includes = [ "*.hx" ]; - }; - nixfmt = { - command = "nixfmt"; - options = [ "--width=80" ]; - includes = [ "*.nix" ]; - }; - keep-sorted = { - command = "keep-sorted"; - includes = [ "*" ]; - }; - }; - }; - }; - - packages = - let - universalPackages = { - docs = import ./docs { inherit pkgs inputs lib; }; - palette-generator = pkgs.callPackage ./palette-generator { }; - }; - - # Testbeds are virtual machines based on NixOS, therefore they are - # only available for Linux systems. - testbedPackages = lib.optionalAttrs (lib.hasSuffix "-linux" system) ( - import ./stylix/testbed.nix { inherit pkgs inputs lib; } - ); - - # Discord is not available on arm64. This workaround filters out - # testbeds using that package, until we have a better way to handle - # this. - testbedPackages' = - if system == "aarch64-linux" then - lib.filterAttrs ( - name: _: !lib.hasPrefix "testbed:discord:vencord" name - ) testbedPackages - else - testbedPackages; - in - universalPackages // testbedPackages'; - } - ) - // { - nixosModules.stylix = - { pkgs, ... }@args: - { - imports = [ - (import ./stylix/nixos inputs) - { - stylix = { - inherit inputs; - paletteGenerator = - self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; - base16 = base16.lib args; - homeManagerIntegration.module = self.homeModules.stylix; - }; - } - ]; - }; - - homeModules.stylix = - { pkgs, ... }@args: - { - imports = [ - (import ./stylix/hm inputs) - { - stylix = { - inherit inputs; - paletteGenerator = - self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; - base16 = base16.lib args; - }; - } - ]; - }; - - darwinModules.stylix = - { pkgs, ... }@args: - { - imports = [ - (import ./stylix/darwin inputs) - { - stylix = { - inherit inputs; - paletteGenerator = - self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; - base16 = base16.lib args; - homeManagerIntegration.module = self.homeModules.stylix; - }; - } - ]; - }; - - nixOnDroidModules.stylix = - { pkgs, ... }@args: - { - imports = [ - (import ./stylix/droid inputs) - { - stylix = { - paletteGenerator = - self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; - base16 = base16.lib args; - homeManagerIntegration.module = self.homeModules.stylix; - }; - } - ]; - }; - } - // - # Drop this alias after 25.11 - nixpkgs.lib.optionalAttrs (!nixpkgs.lib.oldestSupportedReleaseIsAtLeast 2511) { - homeManagerModules = builtins.warn "stylix: flake output `homeManagerModules` has been renamed to `homeModules`" self.homeModules; - }; + systems = import systems; + }; } diff --git a/flake/default.nix b/flake/default.nix new file mode 100644 index 00000000..f0978e97 --- /dev/null +++ b/flake/default.nix @@ -0,0 +1,43 @@ +{ + imports = [ + ./dev-shell.nix + ./modules.nix + ./packages.nix + ./pre-commit.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; [ + nixfmt-rfc-style + stylish-haskell + keep-sorted + ]; + + settings = { + on-unmatched = "info"; + tree-root-file = "flake.nix"; + + formatter = { + stylish-haskell = { + command = "stylish-haskell"; + includes = [ "*.hx" ]; + }; + nixfmt = { + command = "nixfmt"; + options = [ "--width=80" ]; + includes = [ "*.nix" ]; + }; + keep-sorted = { + command = "keep-sorted"; + includes = [ "*" ]; + }; + }; + }; + }; + }; +} diff --git a/flake/dev-shell.nix b/flake/dev-shell.nix new file mode 100644 index 00000000..11ae8221 --- /dev/null +++ b/flake/dev-shell.nix @@ -0,0 +1,51 @@ +{ + perSystem = + { + pkgs, + config, + inputs', + ... + }: + let + stylix-check = pkgs.writeShellApplication { + name = "stylix-check"; + runtimeInputs = with pkgs; [ + nix + nix-fast-build + ]; + text = '' + cores="$(nproc)" + system="$(nix eval --expr builtins.currentSystem --impure --raw)" + nix-fast-build \ + --eval-max-memory-size 512 \ + --eval-workers "$cores" \ + --flake ".#checks.$system" \ + --no-link \ + --skip-cached \ + "$@" + ''; + }; + in + { + devShells = { + default = pkgs.mkShell { + # Install git-hooks when activating the shell + shellHook = config.pre-commit.installationScript; + + packages = + [ + stylix-check + inputs'.home-manager.packages.default + config.formatter + ] + ++ config.pre-commit.settings.enabledPackages + ++ config.formatter.runtimeInputs; + }; + + ghc = pkgs.mkShell { + inputsFrom = [ config.devShells.default ]; + packages = [ pkgs.ghc ]; + }; + }; + }; +} diff --git a/flake/modules.nix b/flake/modules.nix new file mode 100644 index 00000000..986bd7e7 --- /dev/null +++ b/flake/modules.nix @@ -0,0 +1,80 @@ +{ + inputs, + self, + lib, + ... +}: +{ + flake = { + nixosModules.stylix = + { pkgs, ... }@args: + { + imports = [ + (import "${self}/stylix/nixos" inputs) + { + stylix = { + inherit inputs; + paletteGenerator = + self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; + base16 = inputs.base16.lib args; + homeManagerIntegration.module = self.homeModules.stylix; + }; + } + ]; + }; + + # Drop this alias after 26.05 + homeManagerModules = lib.mkIf (lib.oldestSupportedReleaseIsAtLeast 2511) ( + builtins.warn "stylix: flake output `homeManagerModules` has been renamed to `homeModules`" self.homeModules + ); + + homeModules.stylix = + { pkgs, ... }@args: + { + imports = [ + (import "${self}/stylix/hm" inputs) + { + stylix = { + inherit inputs; + paletteGenerator = + self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; + base16 = inputs.base16.lib args; + }; + } + ]; + }; + + darwinModules.stylix = + { pkgs, ... }@args: + { + imports = [ + (import "${self}/stylix/darwin" inputs) + { + stylix = { + inherit inputs; + paletteGenerator = + self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; + base16 = inputs.base16.lib args; + homeManagerIntegration.module = self.homeModules.stylix; + }; + } + ]; + }; + + nixOnDroidModules.stylix = + { pkgs, ... }@args: + { + imports = [ + (import "${self}/stylix/droid" inputs) + { + stylix = { + paletteGenerator = + self.packages.${pkgs.stdenv.hostPlatform.system}.palette-generator; + base16 = inputs.base16.lib args; + homeManagerIntegration.module = self.homeModules.stylix; + }; + } + ]; + }; + }; +} diff --git a/flake/packages.nix b/flake/packages.nix new file mode 100644 index 00000000..8e3c1c3b --- /dev/null +++ b/flake/packages.nix @@ -0,0 +1,39 @@ +{ + lib, + inputs, + self, + ... +}: +{ + + perSystem = + { pkgs, system, ... }: + { + packages = + let + # Testbeds are virtual machines based on NixOS, therefore they are + # only available for Linux systems. + testbedPackages = lib.mkIf (lib.hasSuffix "-linux" system) ( + import "${self}/stylix/testbed.nix" { inherit pkgs inputs lib; } + ); + + # Discord is not available on arm64. This workaround filters out + # testbeds using that package, until we have a better way to handle + # this. + testbedPackages' = + if system == "aarch64-linux" then + lib.filterAttrs ( + name: _: !lib.hasPrefix "testbed:discord:vencord" name + ) testbedPackages + else + testbedPackages; + in + lib.mkMerge [ + testbedPackages' + { + docs = import "${self}/docs" { inherit pkgs inputs lib; }; + palette-generator = pkgs.callPackage "${self}/palette-generator" { }; + } + ]; + }; +} diff --git a/flake/pre-commit.nix b/flake/pre-commit.nix new file mode 100644 index 00000000..dda19542 --- /dev/null +++ b/flake/pre-commit.nix @@ -0,0 +1,35 @@ +{ inputs, ... }: +{ + imports = [ + inputs.git-hooks.flakeModule + ]; + + perSystem = + { config, ... }: + { + pre-commit = { + check.enable = true; + + settings.hooks = { + deadnix.enable = true; + editorconfig-checker.enable = true; + hlint.enable = true; + + treefmt = { + enable = true; + package = config.formatter; + }; + + statix.enable = true; + typos = { + enable = true; + settings.configuration = '' + [default.extend-identifiers] + MrSom3body="MrSom3body" + ''; + }; + yamllint.enable = true; + }; + }; + }; +}