diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 53dbabff..2a7285f6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,9 +24,6 @@ jobs: steps: - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v18 - with: - extra_nix_config: | - experimental-features = nix-command flakes - uses: cachix/cachix-action@v12 with: name: pre-commit-hooks diff --git a/default.nix b/default.nix index ede9812f..626c1d0e 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,10 @@ -let - pkgs = import ./nix { }; -in -pkgs.packages // pkgs.checks // { inherit (pkgs) run; } +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).defaultNix.lib.${builtins.currentSystem} diff --git a/flake.lock b/flake.lock index e7c07696..881f1cfb 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,28 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { - "lastModified": 1667077288, - "narHash": "sha256-bdC8sFNDpT0HK74u9fUkpbf1MEzVYJ+ka7NXCdgBoaA=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "6ee9ebb6b1ee695d2cacc4faa053a7b9baa76817", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -15,13 +31,31 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1667292599, - "narHash": "sha256-7ISOUI1aj6UKMPIL+wwthENL22L3+A9V+jS8Is3QsRo=", + "lastModified": 1632846328, + "narHash": "sha256-sFi6YtlGK30TBB9o6CW7LG9mYHkgtKeWbSLAjjrNTX0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ef2f213d9659a274985778bff4ca322f3ef3ac68", + "rev": "2b71ddd869ad592510553d09fe89c9709fa26b2b", "type": "github" }, "original": { @@ -29,10 +63,45 @@ "type": "indirect" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1668595291, + "narHash": "sha256-j8cyfbtT5sAYPYwbERgTDzfD48ZernL0/V668eGpXAM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6474d93e007e4d165bcf48e7f87de2175c93d10b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1668765800, + "narHash": "sha256-rC40+/W6Hio7b/RsY8SvQPKNx4WqNcTgfYv8cUMAvJk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "52b2ac8ae18bbad4374ff0dd5aeee0fdf1aea739", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { + "flake-compat": "flake-compat", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" } } }, diff --git a/flake.nix b/flake.nix index aa05906f..42c72896 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,16 @@ { description = "Seamless integration of https://pre-commit.com git hooks with Nix."; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-22.05"; inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + inputs.gitignore.url = "github:hercules-ci/gitignore.nix"; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, flake-utils, gitignore, nixpkgs-stable, ... }: let defaultSystems = [ "aarch64-linux" @@ -24,14 +31,19 @@ } // flake-utils.lib.eachSystem defaultSystems (system: let - exposed = import ./nix { nixpkgs = nixpkgs; inherit system; gitignore-nix-src = null; isFlakes = true; }; + exposed = import ./nix { nixpkgs = nixpkgs; inherit system; gitignore-nix-src = gitignore; isFlakes = true; }; + exposed-stable = import ./nix { nixpkgs = nixpkgs-stable; inherit system; gitignore-nix-src = gitignore; isFlakes = true; }; in { packages = exposed.packages; defaultPackage = exposed.packages.pre-commit; - checks = exposed.checks; + devShell = nixpkgs.legacyPackages.${system}.mkShell { + inherit (exposed.checks.pre-commit-check) shellHook; + }; + + checks = exposed.checks // (builtins.removeAttrs exposed-stable.checks [ "revive" "purs-tidy" ]); lib = { inherit (exposed) run; }; } diff --git a/nix/default.nix b/nix/default.nix index 91215208..2ec99f78 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,7 +1,6 @@ -{ sources ? import ./sources.nix -, system ? builtins.currentSystem -, nixpkgs ? sources.nixpkgs -, gitignore-nix-src ? sources."gitignore.nix" +{ system ? builtins.currentSystem +, nixpkgs +, gitignore-nix-src , isFlakes ? false }: let @@ -25,10 +24,6 @@ let shellcheck.enable = true; nixpkgs-fmt.enable = true; }; - excludes = [ - # autogenerated by niv - "nix/sources.nix$" - ]; }; }; }; diff --git a/nix/run.nix b/nix/run.nix index 35d09eb4..de2402e9 100644 --- a/nix/run.nix +++ b/nix/run.nix @@ -24,7 +24,7 @@ let } // (if isFlakes then { rootSrc = src; } else { - rootSrc = (import gitignore-nix-src { inherit (pkgs) lib; }).gitignoreSource src; + rootSrc = gitignore-nix-src.lib.gitignoreSource src; }); } ]; diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index 7714df8f..00000000 --- a/nix/sources.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "gitignore.nix": { - "branch": "master", - "description": "Nix function for filtering local git sources", - "homepage": "", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "f2ea0f8ff1bce948ccb6b893d15d5ea3efaf1364", - "sha256": "02q2yvakyh9x9h9x9az2rr3h6h0zymhrl0z2xflc6blvz6zzqkf2", - "type": "tarball", - "url": "https://github.com/hercules-ci/gitignore.nix/archive/f2ea0f8ff1bce948ccb6b893d15d5ea3efaf1364.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs": { - "branch": "nixpkgs-unstable", - "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", - "homepage": "https://github.com/NixOS/nixpkgs", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "ef2f213d9659a274985778bff4ca322f3ef3ac68", - "sha256": "06mis36j5g1lz9ahzy7pcbdlnhw45l6gn2zj605ab3ssim88x17c", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/ef2f213d9659a274985778bff4ca322f3ef3ac68.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index c9c3d525..00000000 --- a/nix/sources.nix +++ /dev/null @@ -1,95 +0,0 @@ -# This file has been generated by Niv. - -# A record, from name to path, of the third-party packages -with rec -{ - pkgs = - if hasNixpkgsPath - then - if hasThisAsNixpkgsPath - then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} - else import {} - else - import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; - - sources_nixpkgs = - if builtins.hasAttr "nixpkgs" sources - then sources.nixpkgs - else abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = - { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball { inherit url; } - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = - { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl { inherit url; } - else - fetchurl attrs; - - # A wrapper around pkgs.fetchzip that has inspectable arguments, - # annoyingly this means we have to specify them - fetchzip = { url, sha256 }@attrs: pkgs.fetchzip attrs; - - hasNixpkgsPath = (builtins.tryEval ).success; - hasThisAsNixpkgsPath = - (builtins.tryEval ).success && == ./.; - - sources = builtins.fromJSON (builtins.readFile ./sources.json); - - mapAttrs = builtins.mapAttrs or - ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # borrowed from nixpkgs - functionArgs = f: f.__functionArgs or (builtins.functionArgs f); - callFunctionWith = autoArgs: f: args: - let - auto = builtins.intersectAttrs (functionArgs f) autoArgs; - in - f (auto // args); - - getFetcher = spec: - let - fetcherName = - if builtins.hasAttr "type" spec - then builtins.getAttr "type" spec - else "builtin-tarball"; - in - builtins.getAttr fetcherName { - "tarball" = fetchzip; - "builtin-tarball" = builtins_fetchTarball; - "file" = pkgs.fetchurl; - "builtin-url" = builtins_fetchurl; - }; -}; -# NOTE: spec must _not_ have an "outPath" attribute -mapAttrs ( - _: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec - then - spec // { outPath = callFunctionWith spec (getFetcher spec) {}; } - else spec -) sources diff --git a/nix/tools.nix b/nix/tools.nix index a47b2dbe..18f0be0a 100644 --- a/nix/tools.nix +++ b/nix/tools.nix @@ -21,7 +21,6 @@ , html-tidy , hunspell , luaPackages -, niv , mdsh , nix-linter , nixfmt @@ -40,7 +39,7 @@ , writeScript , writeText , go -, revive +, revive ? null }: { @@ -49,8 +48,9 @@ # TODO: these two should be statically compiled inherit (haskellPackages) brittany fourmolu; inherit (luaPackages) luacheck; - inherit (nodePackages) eslint markdownlint-cli prettier purs-tidy; + inherit (nodePackages) eslint markdownlint-cli prettier; inherit (python39Packages) ansible-lint yamllint; + purs-tidy = nodePackages.purs-tidy or null; cabal2nix-dir = callPackage ./cabal2nix-dir { }; hpack-dir = callPackage ./hpack-dir { }; hunspell = callPackage ./hunspell { }; diff --git a/shell.nix b/shell.nix index 328e7001..6234bb4d 100644 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1,10 @@ -with { pkgs = import ./nix { }; }; - -pkgs.mkShell { - buildInputs = [ pkgs.niv ]; - inherit ((import ./.).pre-commit-check) shellHook; -} +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix