From cfaf6890b1ba276e17acbc3f2692d25647bb81b0 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 6 Dec 2024 19:19:27 +0100 Subject: [PATCH] flake: switch to flake-utils and treefmt-nix Signed-off-by: Sefa Eyeoglu --- .github/workflows/format.yaml | 2 +- README-template.md | 6 +-- README.md | 6 +-- development.nix | 35 +++++++++++++++ flake.lock | 60 +++++++++++++++++++------ flake.nix | 31 ++++++------- parts/module.nix => nixos/default.nix | 12 +---- nvfetcher.toml | 20 ++++----- parts/checks.nix | 21 --------- parts/dev.nix | 48 -------------------- parts/readme.nix | 25 ----------- pkgs/default.nix | 64 ++++++++++----------------- pkgs/overlay.nix | 25 +++++++++++ tools/update-readme.nix | 32 ++++++++++++++ treefmt.nix | 20 +++++++++ 15 files changed, 215 insertions(+), 192 deletions(-) create mode 100644 development.nix rename parts/module.nix => nixos/default.nix (71%) delete mode 100644 parts/checks.nix delete mode 100644 parts/dev.nix delete mode 100644 parts/readme.nix create mode 100644 pkgs/overlay.nix create mode 100644 tools/update-readme.nix create mode 100644 treefmt.nix diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 5755431..880887c 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -15,4 +15,4 @@ jobs: - uses: DeterminateSystems/magic-nix-cache-action@main - name: Check formatting run: | - nix fmt -- --check + nix fmt -- --ci diff --git a/README-template.md b/README-template.md index 9cfd259..5ee81fc 100644 --- a/README-template.md +++ b/README-template.md @@ -28,7 +28,7 @@ is to add the input `github:nix-community/nixpkgs-xr` to your flake and import the convenient NixOS module `nixpkgs-xr.nixosModules.nixpkgs-xr`. See the example below. -> [!IMPORTANT] +> \[!IMPORTANT\] > This module adds the Nixpkgs overlay as well as [the binary cache][binary-cache] for this repository. > If you don't want the binary cache see [manual setup](#manually-setup-flake-overlay) below. @@ -84,7 +84,7 @@ Assuming your NixOS configuration is right in your `flake.nix`, you can write th ### Traditional setup -Compatibility for traditional NixOS setups is provided using [flake-compat][flake-compat]. +Compatibility for traditional NixOS setups is provided using [flake-compat]. You can just add the following snippet to your configuration: ```nix @@ -102,7 +102,7 @@ in } ``` -You can also pin the tarball url using tools like [niv][niv]. +You can also pin the tarball url using tools like [niv]. ## Packages diff --git a/README.md b/README.md index 8e332ed..49ee836 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ is to add the input `github:nix-community/nixpkgs-xr` to your flake and import the convenient NixOS module `nixpkgs-xr.nixosModules.nixpkgs-xr`. See the example below. -> [!IMPORTANT] +> \[!IMPORTANT\] > This module adds the Nixpkgs overlay as well as [the binary cache][binary-cache] for this repository. > If you don't want the binary cache see [manual setup](#manually-setup-flake-overlay) below. @@ -84,7 +84,7 @@ Assuming your NixOS configuration is right in your `flake.nix`, you can write th ### Traditional setup -Compatibility for traditional NixOS setups is provided using [flake-compat][flake-compat]. +Compatibility for traditional NixOS setups is provided using [flake-compat]. You can just add the following snippet to your configuration: ```nix @@ -102,7 +102,7 @@ in } ``` -You can also pin the tarball url using tools like [niv][niv]. +You can also pin the tarball url using tools like [niv]. ## Packages diff --git a/development.nix b/development.nix new file mode 100644 index 0000000..a6342ec --- /dev/null +++ b/development.nix @@ -0,0 +1,35 @@ +# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu +# +# SPDX-License-Identifier: MIT +{ + flake-utils, + nixpkgs, + self, + treefmt-nix, + ... +}: +flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs.lib) mapAttrs' nameValuePair; + + treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; + + devShellChecks = mapAttrs' (n: nameValuePair "devShell-${n}") self.devShells.${system}; + in + { + devShells.default = pkgs.mkShellNoCC { + packages = [ + pkgs.nvfetcher + pkgs.reuse + ]; + }; + + checks = devShellChecks // { + formatting = treefmtEval.config.build.check self; + }; + + formatter = treefmtEval.config.build.wrapper; + } +) diff --git a/flake.lock b/flake.lock index fc27ef4..d87bbe3 100644 --- a/flake.lock +++ b/flake.lock @@ -14,23 +14,21 @@ "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" } }, - "flake-parts": { + "flake-utils": { "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] + "systems": "systems" }, "locked": { - "lastModified": 1733312601, - "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "flake-parts", + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, @@ -53,8 +51,44 @@ "root": { "inputs": { "flake-compat": "flake-compat", - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1733440889, + "narHash": "sha256-qKL3vjO+IXFQ0nTinFDqNq/sbbnnS5bMI1y0xX215fU=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "50862ba6a8a0255b87377b9d2d4565e96f29b410", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 4a746fa..389f9cb 100644 --- a/flake.nix +++ b/flake.nix @@ -13,26 +13,21 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; + flake-utils.url = "github:numtide/flake-utils"; flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = - inputs@{ flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ - "x86_64-linux" - "aarch64-linux" - ]; - imports = [ - ./parts/checks.nix - ./parts/dev.nix - ./parts/module.nix - ./parts/readme.nix - ./pkgs - ]; - }; + { flake-utils, ... }@inputs: + flake-utils.lib.meld inputs [ + ./development.nix + ./nixos + ./pkgs + ./pkgs/overlay.nix + ./tools/update-readme.nix + ]; } diff --git a/parts/module.nix b/nixos/default.nix similarity index 71% rename from parts/module.nix rename to nixos/default.nix index 7badbdf..7a028f8 100644 --- a/parts/module.nix +++ b/nixos/default.nix @@ -1,28 +1,20 @@ # SPDX-FileCopyrightText: 2023 Sefa Eyeoglu +# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu # # SPDX-License-Identifier: MIT { self, ... }: { - flake.nixosModules.nixpkgs-xr = + nixosModules.nixpkgs-xr = { config, lib, ... }: let inherit (lib) mkEnableOption mkIf mkOption - mkRemovedOptionModule ; cfg = config.nixpkgs.xr; in { - imports = [ - (mkRemovedOptionModule [ - "nixpkgs" - "xr" - "enableUnstripped" - ] "The nixpkgs-xr unstripped overlay has been removed. Please create your own overlay.") - ]; - options.nixpkgs.xr.enable = mkEnableOption "nixpkgs-xr overlay" // mkOption { default = true; }; config = mkIf cfg.enable { diff --git a/nvfetcher.toml b/nvfetcher.toml index abc2952..1ef6379 100644 --- a/nvfetcher.toml +++ b/nvfetcher.toml @@ -3,25 +3,25 @@ # SPDX-License-Identifier: CC0-1.0 [envision-unwrapped] -src.git = "https://gitlab.com/gabmus/envision.git" +cargo_locks = ["Cargo.lock"] fetch.git = "https://gitlab.com/gabmus/envision.git" +src.git = "https://gitlab.com/gabmus/envision.git" + +[index_camera_passthrough] cargo_locks = ["Cargo.lock"] +fetch.git = "https://github.com/yshui/index_camera_passthrough.git" +src.git = "https://github.com/yshui/index_camera_passthrough.git" [monado] -src.git = "https://gitlab.freedesktop.org/monado/monado.git" fetch.git = "https://gitlab.freedesktop.org/monado/monado.git" +src.git = "https://gitlab.freedesktop.org/monado/monado.git" [opencomposite] -src.git = "https://gitlab.com/znixian/OpenOVR.git" fetch.git = "https://gitlab.com/znixian/OpenOVR.git" git.fetchSubmodules = true - -[index_camera_passthrough] -src.git = "https://github.com/yshui/index_camera_passthrough.git" -fetch.git = "https://github.com/yshui/index_camera_passthrough.git" -cargo_locks = ["Cargo.lock"] +src.git = "https://gitlab.com/znixian/OpenOVR.git" [wlx-overlay-s] -src.git = "https://github.com/galister/wlx-overlay-s.git" -fetch.git = "https://github.com/galister/wlx-overlay-s.git" cargo_locks = ["Cargo.lock"] +fetch.git = "https://github.com/galister/wlx-overlay-s.git" +src.git = "https://github.com/galister/wlx-overlay-s.git" diff --git a/parts/checks.nix b/parts/checks.nix deleted file mode 100644 index 1236faa..0000000 --- a/parts/checks.nix +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Sefa Eyeoglu -# -# SPDX-License-Identifier: MIT -{ lib, ... }: -{ - perSystem = - { config, pkgs, ... }: - let - inherit (lib) filterAttrs mapAttrs' nameValuePair; - - packages' = filterAttrs ( - _: pkg: !pkg.meta.broken && (lib.meta.availableOn pkgs.stdenv.hostPlatform pkg) - ) config.packages; - - packageChecks = mapAttrs' (n: nameValuePair "package-${n}") packages'; - devShellChecks = mapAttrs' (n: nameValuePair "devShell-${n}") config.devShells; - in - { - checks = packageChecks // devShellChecks; - }; -} diff --git a/parts/dev.nix b/parts/dev.nix deleted file mode 100644 index 4382743..0000000 --- a/parts/dev.nix +++ /dev/null @@ -1,48 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Sefa Eyeoglu -# SPDX-FileCopyrightText: 2023 Naïm Favier -# -# SPDX-License-Identifier: MIT -{ - perSystem = - { pkgs, ... }: - { - devShells.default = pkgs.mkShell { - packages = with pkgs; [ - nvfetcher - reuse - ]; - }; - - formatter = pkgs.writeShellApplication { - name = "nixpkgs-xr-format"; - - runtimeInputs = [ pkgs.nixfmt-rfc-style ]; - text = '' - nixfmt_args=() - while [[ $# -gt 0 ]]; do - case "$1" in - .) - # ignore "." parameter passed by nix fmt - shift - ;; - -c|--check) - nixfmt_args+=("$1") - shift - ;; - *) - echo "Unknown option $1" >&2 - exit 1 - ;; - esac - done - - git_root=$(git rev-parse --show-toplevel) - - git ls-files -z --cached --full-name -- ":!:_sources/" \ - | grep -z '\.nix$' \ - | sed -z "s|^|$git_root/|" \ - | xargs -0 nixfmt "$@" - ''; - }; - }; -} diff --git a/parts/readme.nix b/parts/readme.nix deleted file mode 100644 index a287ea4..0000000 --- a/parts/readme.nix +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Sefa Eyeoglu -# -# SPDX-License-Identifier: MIT -{ lib, ... }: -{ - perSystem = - { pkgs, self', ... }: - let - inherit (builtins) attrNames; - inherit (lib) concatMapStringsSep; - in - { - apps.genReadme.program = pkgs.writeShellApplication { - name = "genReadme"; - text = '' - cat ${ - pkgs.substituteAll { - src = ../README-template.md; - packageNames = concatMapStringsSep "\n" (name: "- `${name}`") (attrNames self'.packages); - } - } > README.md - ''; - }; - }; -} diff --git a/pkgs/default.nix b/pkgs/default.nix index efe6afe..10533bd 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -2,49 +2,33 @@ # # SPDX-License-Identifier: MIT { - lib, + flake-utils, + nixpkgs, self, - inputs, ... }: -let - inherit (lib) - composeManyExtensions - filterAttrs - isDerivation - makeScope - ; -in -{ - # NOTE: Currying prev arg - flake.overlays = { - default = composeManyExtensions [ - (final: _: { - xrSources = final.callPackage ../_sources/generated.nix { }; - }) - - # New packaged added by us - (import "${inputs.nixpkgs}/pkgs/top-level/by-name-overlay.nix" ./by-name) - - # Overridden packages - (import ./overrides/envision-unwrapped.nix) - (import ./overrides/monado.nix) - (import ./overrides/opencomposite.nix) - (import ./overrides/opencomposite-vendored.nix) - (import ./overrides/wlx-overlay-s.nix) - ]; +flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; - unstripped = throw ".overlays.unstripped has been dropped, please define your own overlay for this."; - }; + inherit (lib) + filterAttrs + isDerivation + makeScope + mapAttrs' + nameValuePair + ; - perSystem = - { pkgs, ... }: - { - packages = - let - scope = makeScope pkgs.newScope (final: self.overlays.default (pkgs // final) pkgs); - in - filterAttrs (_: isDerivation) scope; - }; + scope = makeScope pkgs.newScope (final: self.overlays.default (pkgs // final) pkgs); -} + workingPackages = filterAttrs (_: pkg: !pkg.meta.broken) self.packages.${system}; + in + { + packages = filterAttrs ( + _: pkg: isDerivation pkg && (lib.meta.availableOn pkgs.stdenv.hostPlatform pkg) + ) scope; + checks = mapAttrs' (n: nameValuePair "package-${n}") workingPackages; + } +) diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix new file mode 100644 index 0000000..b78d3b6 --- /dev/null +++ b/pkgs/overlay.nix @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2023 Sefa Eyeoglu +# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu +# +# SPDX-License-Identifier: MIT +{ nixpkgs, ... }: +let + inherit (nixpkgs.lib) composeManyExtensions; +in +{ + overlays.default = composeManyExtensions [ + (final: _: { + xrSources = final.callPackage ../_sources/generated.nix { }; + }) + + # New packaged added by us + (import "${nixpkgs}/pkgs/top-level/by-name-overlay.nix" ./by-name) + + # Overridden packages + (import ./overrides/envision-unwrapped.nix) + (import ./overrides/monado.nix) + (import ./overrides/opencomposite.nix) + (import ./overrides/opencomposite-vendored.nix) + (import ./overrides/wlx-overlay-s.nix) + ]; +} diff --git a/tools/update-readme.nix b/tools/update-readme.nix new file mode 100644 index 0000000..c30d45e --- /dev/null +++ b/tools/update-readme.nix @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu +# +# SPDX-License-Identifier: MIT +{ + flake-utils, + nixpkgs, + self, + ... +}: +flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; + in + { + apps.update-readme = flake-utils.lib.mkApp { + drv = pkgs.writeShellApplication { + name = "update-readme"; + text = '' + cat ${ + pkgs.replaceVars ../README-template.md { + packageNames = lib.concatMapStringsSep "\n" (name: "- `${name}`") ( + builtins.attrNames self.packages.${system} + ); + } + } > README.md + ''; + }; + }; + } +) diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..26617f3 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu +# +# SPDX-License-Identifier: MIT +{ ... }: +{ + projectRootFile = "flake.nix"; + + programs.actionlint.enable = true; + programs.jsonfmt.enable = true; + programs.mdformat.enable = true; + programs.nixfmt.enable = true; + programs.shfmt.enable = true; + programs.toml-sort.enable = true; + + settings.global.excludes = [ + "_sources/**" + "LICENSES/**" + "**.license" + ]; +}