1
1
mirror of https://github.com/nmattia/niv.git synced 2024-10-06 12:27:35 +03:00

refactor: statix recommendations (#363)

* refactor: Inherit where possible

As recommended by `statix check`.

* refactor: Remove unnecessary parentheses

As recommended by `statix check`.

* refactor: Remove unnecessary comparison with `true`

As recommended by `statix check`.

* refactor: Avoid using deprecated `isNull`

As recommended by `statix check` and the documentation
<https://nixos.org/manual/nix/stable/language/builtins.html#builtins-isNull>.

* refactor: Simplify conditionals

As recommended by `statix check`.

* Update sources version

---------

Co-authored-by: Nicolas Mattia <nicolas@nmattia.com>
This commit is contained in:
Victor Engmark 2023-03-12 11:41:42 +00:00 committed by GitHub
parent de5a4e7d01
commit f275964bb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 21 deletions

View File

@ -7,14 +7,12 @@ let
sourceByRegex = name: src: regexes: sourceByRegex = name: src: regexes:
builtins.path { builtins.path {
filter = ( filter = path: type:
path: type: let
let relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path); accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes;
accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes; in
in accept;
accept
);
inherit name; inherit name;
path = src; path = src;
}; };
@ -61,7 +59,7 @@ let
}; };
}; };
niv = haskellPackages.niv; inherit (haskellPackages) niv;
niv-sdist = pkgs.haskell.lib.sdistTarball niv; niv-sdist = pkgs.haskell.lib.sdistTarball niv;

View File

@ -65,7 +65,7 @@
{ mkDerivation }: { mkDerivation }:
mkDerivation { mkDerivation {
pname = spec.name; pname = spec.name;
version = spec.version; inherit (spec) version;
inherit src; inherit src;
isLibrary = builtins.hasAttr "library" spec; isLibrary = builtins.hasAttr "library" spec;
isExecutable = builtins.hasAttr "executables" spec; isExecutable = builtins.hasAttr "executables" spec;

View File

@ -27,16 +27,17 @@ let
fetch_git = name: spec: fetch_git = name: spec:
let let
ref = ref =
if spec ? ref then spec.ref else spec.ref or (
if spec ? branch then "refs/heads/${spec.branch}" else if spec ? branch then "refs/heads/${spec.branch}" else
if spec ? tag then "refs/tags/${spec.tag}" else if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"
submodules = if spec ? submodules then spec.submodules else false; );
submodules = spec.submodules or false;
submoduleArg = submoduleArg =
let let
nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
emptyArgWithWarning = emptyArgWithWarning =
if submodules == true if submodules
then then
builtins.trace builtins.trace
( (
@ -115,7 +116,7 @@ let
# the path directly as opposed to the fetched source. # the path directly as opposed to the fetched source.
replace = name: drv: replace = name: drv:
let let
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in in
if ersatz == "" then drv else if ersatz == "" then drv else
@ -151,7 +152,7 @@ let
inherit (builtins) lessThan nixVersion fetchTarball; inherit (builtins) lessThan nixVersion fetchTarball;
in in
if lessThan nixVersion "1.12" then if lessThan nixVersion "1.12" then
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
else else
fetchTarball attrs; fetchTarball attrs;
@ -161,7 +162,7 @@ let
inherit (builtins) lessThan nixVersion fetchurl; inherit (builtins) lessThan nixVersion fetchurl;
in in
if lessThan nixVersion "1.12" then if lessThan nixVersion "1.12" then
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
else else
fetchurl attrs; fetchurl attrs;
@ -182,7 +183,7 @@ let
# The "config" used by the fetchers # The "config" used by the fetchers
mkConfig = mkConfig =
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
, sources ? if isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile) , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile)
, system ? builtins.currentSystem , system ? builtins.currentSystem
, pkgs ? mkPkgs sources system , pkgs ? mkPkgs sources system
}: rec { }: rec {

View File

@ -179,6 +179,7 @@ data SourcesNixVersion
| -- Support submodules for git repos | -- Support submodules for git repos
V27 V27
| -- formatting fix | -- formatting fix
-- Apply statix suggestions
V28 V28
deriving stock (Bounded, Enum, Eq) deriving stock (Bounded, Enum, Eq)
@ -252,7 +253,7 @@ sourcesVersionToMD5 = \case
V25 -> "6612caee5814670e5e4d9dd1b71b5f70" V25 -> "6612caee5814670e5e4d9dd1b71b5f70"
V26 -> "937bff93370a064c9000f13cec5867f9" V26 -> "937bff93370a064c9000f13cec5867f9"
V27 -> "8031ba9d8fbbc7401c800d0b84278ec8" V27 -> "8031ba9d8fbbc7401c800d0b84278ec8"
V28 -> "2ed0d91d652b28d99f14659144a0af28" V28 -> "26ed55356db7673935329210a4f8c4a5"
-- | The MD5 sum of ./nix/sources.nix -- | The MD5 sum of ./nix/sources.nix
sourcesNixMD5 :: IO T.Text sourcesNixMD5 :: IO T.Text