From f2091d7a5798174eb0f5306ec4940e136d9490d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Thu, 17 Sep 2020 15:55:08 +0200 Subject: [PATCH 1/6] NixOS 20.09 --- nix/sources.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index 52aceb30..d4588416 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -36,15 +36,15 @@ "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { - "branch": "nixos-20.03", + "branch": "nixos-20.09", "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": "99a3d7a86fce9e9c9f23b3e304d7d2b1270a12b8", - "sha256": "0i40cl3n6600z2lkwrpiy28dcnv2r63fcgfswj91aaf1xfn2chql", + "rev": "3b8ddb2f1ee6f4c0794fb6dfbd273c3599492b76", + "sha256": "06hgvyd8ry4i49dmjxh5n6wv1j5ifpp7i3a7bjz62san0q6d0j35", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/99a3d7a86fce9e9c9f23b3e304d7d2b1270a12b8.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/3b8ddb2f1ee6f4c0794fb6dfbd273c3599492b76.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } From b840cb825611fb144471241325243731c980a9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Thu, 17 Sep 2020 16:02:06 +0200 Subject: [PATCH 2/6] use upstream cabal-fmt --- nix/default.nix | 23 ++++++----------------- nix/sources.json | 12 ------------ 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index 17ab931f..ce4fe515 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -5,23 +5,12 @@ let overlay = _: pkgs: - let - cabal-fmt = - pkgs.haskellPackages.callCabal2nix "cabal-fmt" sources.cabal-fmt {}; - in - { - inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter; - hindent = - pkgs.haskellPackages.callCabal2nix "hindent" sources.hindent {}; - cabal-fmt = - cabal-fmt.overrideScope ( - self: super: - { - Cabal = self.Cabal_3_0_0_0; - } - ); - packages = pkgs.callPackages ./packages.nix {}; - }; + { + inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter; + cabal-fmt = pkgs.haskellPackages.cabal-fmt; + hindent = pkgs.haskellPackages.callCabal2nix "hindent" sources.hindent {}; + packages = pkgs.callPackages ./packages.nix {}; + }; in import sources.nixpkgs { overlays = [ overlay ]; diff --git a/nix/sources.json b/nix/sources.json index d4588416..663eaec2 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -1,16 +1,4 @@ { - "cabal-fmt": { - "branch": "master", - "description": "An experiment of formatting .cabal files", - "homepage": null, - "owner": "phadej", - "repo": "cabal-fmt", - "rev": "177b4ca8a446682ee91c536a5492157c1e232864", - "sha256": "1yir989pl2aizlv9wsf5amrixdayf1rc97n8jwfy0f63szrw1rf9", - "type": "tarball", - "url": "https://github.com/phadej/cabal-fmt/archive/177b4ca8a446682ee91c536a5492157c1e232864.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, "gitignore.nix": { "branch": "master", "description": "Nix function for filtering local git sources", From 8f9764779f93b3163bf5b385ceb97dabcb92525a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Thu, 17 Sep 2020 16:14:03 +0200 Subject: [PATCH 3/6] format --- default.nix | 2 +- modules/hooks.nix | 4 +- modules/pre-commit.nix | 221 ++++++++++++++++++++--------------------- nix/default.nix | 15 ++- nix/lazyAttrsOf.nix | 100 +++++++++---------- nix/packages.nix | 3 +- nix/run.nix | 9 +- nix/tools.nix | 2 +- shell.nix | 2 +- 9 files changed, 177 insertions(+), 181 deletions(-) diff --git a/default.nix b/default.nix index 9d150316..50a05595 100644 --- a/default.nix +++ b/default.nix @@ -1 +1 @@ -let pkgs = import ./nix {}; in pkgs.packages +let pkgs = import ./nix { }; in pkgs.packages diff --git a/modules/hooks.nix b/modules/hooks.nix index 5349a0da..9cba82a8 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -12,7 +12,7 @@ in mkOption { type = types.listOf types.str; description = "Haskell language extensions to enable"; - default = []; + default = [ ]; }; }; nix-linter = @@ -22,7 +22,7 @@ in type = types.listOf types.str; description = "Available checks (See `nix-linter --help-for [CHECK]` for more details)"; - default = []; + default = [ ]; }; }; }; diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index 3d2bbf6f..bfdc5e34 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -1,7 +1,5 @@ { config, lib, pkgs, ... }: - let - inherit (lib) attrNames concatStringsSep @@ -21,122 +19,123 @@ let hookType = types.submodule ( { config, name, ... }: - { - options = - { - enable = - mkOption { - type = types.bool; - description = "Whether to enable this pre-commit hook."; - default = false; - }; - raw = - mkOption { - type = types.attrsOf types.unspecified; - description = - '' - Raw fields of a pre-commit hook. This is mostly for internal use but - exposed in case you need to work around something. + { + options = + { + enable = + mkOption { + type = types.bool; + description = "Whether to enable this pre-commit hook."; + default = false; + }; + raw = + mkOption { + type = types.attrsOf types.unspecified; + description = + '' + Raw fields of a pre-commit hook. This is mostly for internal use but + exposed in case you need to work around something. - Default: taken from the other hook options. - ''; - }; - name = - mkOption { - type = types.str; - default = name; - defaultText = literalExample "internal name, same as id"; - description = - '' - The name of the hook - shown during hook execution. - ''; - }; - entry = - mkOption { - type = types.str; - description = - '' - The entry point - the executable to run. entry can also contain arguments that will not be overridden such as entry: autopep8 -i. - ''; - }; - language = - mkOption { - type = types.str; - description = - '' - The language of the hook - tells pre-commit how to install the hook. - ''; - default = "system"; - }; - files = - mkOption { - type = types.str; - description = - '' - The pattern of files to run on. - ''; - default = ""; - }; - types = - mkOption { - type = types.listOf types.str; - description = - '' - List of file types to run on. See Filtering files with types (https://pre-commit.com/#plugins). - ''; - default = [ "file" ]; - }; - description = - mkOption { - type = types.str; - description = - '' - Description of the hook. used for metadata purposes only. - ''; - default = ""; - }; - excludes = - mkOption { - type = types.listOf types.str; - description = - '' - Exclude files that were matched by these patterns. - ''; - default = []; - }; - pass_filenames = - mkOption { - type = types.bool; - description = "Whether to pass filenames as arguments to the entry point."; - default = true; - }; - }; - config = - { - raw = - { - inherit (config) name entry language files types pass_filenames; - id = name; - exclude = mergeExcludes config.excludes; - }; - }; - } + Default: taken from the other hook options. + ''; + }; + name = + mkOption { + type = types.str; + default = name; + defaultText = literalExample "internal name, same as id"; + description = + '' + The name of the hook - shown during hook execution. + ''; + }; + entry = + mkOption { + type = types.str; + description = + '' + The entry point - the executable to run. entry can also contain arguments that will not be overridden such as entry: autopep8 -i. + ''; + }; + language = + mkOption { + type = types.str; + description = + '' + The language of the hook - tells pre-commit how to install the hook. + ''; + default = "system"; + }; + files = + mkOption { + type = types.str; + description = + '' + The pattern of files to run on. + ''; + default = ""; + }; + types = + mkOption { + type = types.listOf types.str; + description = + '' + List of file types to run on. See Filtering files with types (https://pre-commit.com/#plugins). + ''; + default = [ "file" ]; + }; + description = + mkOption { + type = types.str; + description = + '' + Description of the hook. used for metadata purposes only. + ''; + default = ""; + }; + excludes = + mkOption { + type = types.listOf types.str; + description = + '' + Exclude files that were matched by these patterns. + ''; + default = [ ]; + }; + pass_filenames = + mkOption { + type = types.bool; + description = "Whether to pass filenames as arguments to the entry point."; + default = true; + }; + }; + config = + { + raw = + { + inherit (config) name entry language files types pass_filenames; + id = name; + exclude = mergeExcludes config.excludes; + }; + }; + } ); mergeExcludes = excludes: - if excludes == [] then "^$" else "(${concatStringsSep "|" excludes})"; + if excludes == [ ] then "^$" else "(${concatStringsSep "|" excludes})"; enabledHooks = filterAttrs (id: value: value.enable) cfg.hooks; processedHooks = mapAttrsToList (id: value: value.raw // { inherit id; }) enabledHooks; configFile = - runCommand "pre-commit-config.json" { - buildInputs = [ pkgs.jq ]; - passAsFile = [ "rawJSON" ]; - rawJSON = builtins.toJSON cfg.rawConfig; - } '' + runCommand "pre-commit-config.json" + { + buildInputs = [ pkgs.jq ]; + passAsFile = [ "rawJSON" ]; + rawJSON = builtins.toJSON cfg.rawConfig; + } '' { echo '# DO NOT MODIFY'; echo '# This file was generated by nix-pre-commit-hooks'; @@ -200,7 +199,7 @@ in ''; # This default is for when the module is the entry point rather than # /default.nix. /default.nix will override this for efficiency. - default = (import ../nix { inherit (pkgs) system; }).callPackage ../nix/tools.nix {}; + default = (import ../nix { inherit (pkgs) system; }).callPackage ../nix/tools.nix { }; defaultText = literalExample ''nix-pre-commit-hooks-pkgs.callPackage tools-dot-nix { inherit (pkgs) system; }''; }; @@ -212,7 +211,7 @@ in '' The hook definitions. ''; - default = {}; + default = { }; }; run = @@ -255,7 +254,7 @@ in '' Exclude files that were matched by these patterns. ''; - default = []; + default = [ ]; }; rawConfig = @@ -284,7 +283,7 @@ in hooks = processedHooks; } ]; - } // lib.optionalAttrs (cfg.excludes != []) { + } // lib.optionalAttrs (cfg.excludes != [ ]) { exclude = mergeExcludes cfg.excludes; }; diff --git a/nix/default.nix b/nix/default.nix index ce4fe515..22b5e056 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,19 +1,18 @@ { sources ? import ./sources.nix , system ? builtins.currentSystem }: - let overlay = _: pkgs: - { - inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter; - cabal-fmt = pkgs.haskellPackages.cabal-fmt; - hindent = pkgs.haskellPackages.callCabal2nix "hindent" sources.hindent {}; - packages = pkgs.callPackages ./packages.nix {}; - }; + { + inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter; + cabal-fmt = pkgs.haskellPackages.cabal-fmt; + hindent = pkgs.haskellPackages.callCabal2nix "hindent" sources.hindent { }; + packages = pkgs.callPackages ./packages.nix { }; + }; in import sources.nixpkgs { overlays = [ overlay ]; - config = {}; + config = { }; inherit system; } diff --git a/nix/lazyAttrsOf.nix b/nix/lazyAttrsOf.nix index 22ac7886..6adc1ff9 100644 --- a/nix/lazyAttrsOf.nix +++ b/nix/lazyAttrsOf.nix @@ -38,66 +38,66 @@ let then _loc: _defs: _n: args.default else defaultLazyAttrsOfDefaultFunction }: - let - ao = types.attrsOf elemType; - in - ao // { - name = "lazyAttrsOf"; - description = "attribute set of lazily merged ${elemType.description}s"; - check = lib.isAttrs; + let + ao = types.attrsOf elemType; + in + ao // { + name = "lazyAttrsOf"; + description = "attribute set of lazily merged ${elemType.description}s"; + check = lib.isAttrs; - # TODO: add v location to mkIf error message - # TODO: allow specifying a default value in such cases - merge = loc: defs: - mapAttrs + # TODO: add v location to mkIf error message + # TODO: allow specifying a default value in such cases + merge = loc: defs: + mapAttrs + ( + n: v: + let + defFiles = lib.showFiles (map (def: def.file) defs); + in + builtins.addErrorContext + "while evaluating the '${n}' attribute of ${lib.showOption loc} defined in ${defFiles}" + v.value or (defaultFunction loc defs n) + ) + ( + zipAttrsWith ( - n: v: - let - defFiles = lib.showFiles (map (def: def.file) defs); - in - builtins.addErrorContext - "while evaluating the '${n}' attribute of ${lib.showOption loc} defined in ${defFiles}" - v.value or (defaultFunction loc defs n) + name: defs: + (mergeDefinitions (loc ++ [ name ]) elemType defs).optionalValue // { inherit defs; } ) + # Push down position info. ( - zipAttrsWith - ( - name: defs: - (mergeDefinitions (loc ++ [ name ]) elemType defs).optionalValue // { inherit defs; } - ) - # Push down position info. - ( - map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) - defs - ) - ); - }; + map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) + defs + ) + ); + }; defaultLazyAttrsOfDefaultFunction = loc: defs: n: - let - defFiles = lib.showFiles (map (def: def.file) defs); - in - throw '' - A value is missing from a lazy attribute set. - in option ${lib.showOption loc} - defined in ${defFiles} + let + defFiles = lib.showFiles (map (def: def.file) defs); + in + throw '' + A value is missing from a lazy attribute set. + in option ${lib.showOption loc} + defined in ${defFiles} - Module users: - Please use lib.optionalAttrs instead of mkIf when defining conditional values - for lazyAttrsOf options. + Module users: + Please use lib.optionalAttrs instead of mkIf when defining conditional values + for lazyAttrsOf options. - The purpose of a lazy attribute set option is to allow the set of keys to be - determined without evaluating the values. This can only be done by ignoring - any mkIfs until it's too late. + The purpose of a lazy attribute set option is to allow the set of keys to be + determined without evaluating the values. This can only be done by ignoring + any mkIfs until it's too late. - Module authors: - In some cases, this problem can be worked around by adding a default value, - but do consider that the key set is going to be different for {} as opposed - to { x = mkIf false y; }! - Only add a default if you know that the set of attribute names is not used - in any significant way. - ''; + Module authors: + In some cases, this problem can be worked around by adding a default value, + but do consider that the key set is going to be different for {} as opposed + to { x = mkIf false y; }! + Only add a default if you know that the set of attribute names is not used + in any significant way. + ''; # TODO when upstreaming, add automated tests, with cases diff --git a/nix/packages.nix b/nix/packages.nix index 4a7d7dbd..d4c2a379 100644 --- a/nix/packages.nix +++ b/nix/packages.nix @@ -1,7 +1,6 @@ { niv, gitAndTools, callPackage }: - let - tools = callPackage ./tools.nix {}; + tools = callPackage ./tools.nix { }; in tools // rec { inherit niv; diff --git a/nix/run.nix b/nix/run.nix index 601d402e..7e85c630 100644 --- a/nix/run.nix +++ b/nix/run.nix @@ -1,12 +1,11 @@ builtinStuff@{ pkgs, tools, pre-commit, git, runCommand, writeText, writeScript, lib }: { src -, hooks ? {} -, excludes ? [] -, tools ? {} -, settings ? {} +, hooks ? { } +, excludes ? [ ] +, tools ? { } +, settings ? { } }: - let sources = import ./sources.nix; diff --git a/nix/tools.nix b/nix/tools.nix index de115d7c..52656b4e 100644 --- a/nix/tools.nix +++ b/nix/tools.nix @@ -27,5 +27,5 @@ inherit (elmPackages) elm-format; inherit (haskellPackages) brittany hpack; inherit (pythonPackages) yamllint; - terraform-fmt = callPackage ./terraform-fmt {}; + terraform-fmt = callPackage ./terraform-fmt { }; } diff --git a/shell.nix b/shell.nix index f38bbdc3..328e7001 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ -with { pkgs = import ./nix {}; }; +with { pkgs = import ./nix { }; }; pkgs.mkShell { buildInputs = [ pkgs.niv ]; From b316c8d8e2cd532b71d2bfad4d71d599f215ff8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Tue, 6 Oct 2020 19:35:04 +0200 Subject: [PATCH 4/6] remove bors --- bors.toml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 bors.toml diff --git a/bors.toml b/bors.toml deleted file mode 100644 index 8d423201..00000000 --- a/bors.toml +++ /dev/null @@ -1,5 +0,0 @@ -status = [ - "ci/hercules/derivations", - "ci/hercules/evaluation", -] -delete_merged_branches = true From 57476b99efb4229a3e148107c280b558a3394bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Tue, 6 Oct 2020 19:42:08 +0200 Subject: [PATCH 5/6] bump nixpkgs --- nix/sources.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index 663eaec2..cac1779e 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -24,15 +24,15 @@ "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { - "branch": "nixos-20.09", + "branch": "release-20.09", "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": "3b8ddb2f1ee6f4c0794fb6dfbd273c3599492b76", - "sha256": "06hgvyd8ry4i49dmjxh5n6wv1j5ifpp7i3a7bjz62san0q6d0j35", + "rev": "b60f5e90cf20d08be6b26177b50b44f2c6d653f5", + "sha256": "1pfk4gmsr1z3wz5f3crfy5r306d157ncqaidnmbrcjm812iy2baq", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/3b8ddb2f1ee6f4c0794fb6dfbd273c3599492b76.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/b60f5e90cf20d08be6b26177b50b44f2c6d653f5.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } From 9ef0d41307cfba042cc9fa65cc06875368f49c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Tue, 6 Oct 2020 19:49:27 +0200 Subject: [PATCH 6/6] bump hindent --- nix/sources.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index cac1779e..a07009f1 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -17,10 +17,10 @@ "homepage": null, "owner": "chrisdone", "repo": "hindent", - "rev": "1583be4a8a01b765841f7306284528ae713abb7b", - "sha256": "sha256:1l8v3vq3yw7zr1yxyscfw8lggcf0klnyszhv18505c6myybp2dkp", + "rev": "a75d4033969ecf7d4d0a5eb985d3d1abb3b9301f", + "sha256": "0g9dm3mr7wi7bk55fvswv0zcw1khgyr2bmchrg6ks82jc9znxkr6", "type": "tarball", - "url": "https://github.com/chrisdone/hindent/archive/1583be4a8a01b765841f7306284528ae713abb7b.tar.gz", + "url": "https://github.com/chrisdone/hindent/archive/a75d4033969ecf7d4d0a5eb985d3d1abb3b9301f.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": {