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:
parent
de5a4e7d01
commit
f275964bb0
@ -7,14 +7,12 @@ let
|
||||
|
||||
sourceByRegex = name: src: regexes:
|
||||
builtins.path {
|
||||
filter = (
|
||||
path: type:
|
||||
filter = path: type:
|
||||
let
|
||||
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
|
||||
accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes;
|
||||
in
|
||||
accept
|
||||
);
|
||||
accept;
|
||||
inherit name;
|
||||
path = src;
|
||||
};
|
||||
@ -61,7 +59,7 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
niv = haskellPackages.niv;
|
||||
inherit (haskellPackages) niv;
|
||||
|
||||
niv-sdist = pkgs.haskell.lib.sdistTarball niv;
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
||||
{ mkDerivation }:
|
||||
mkDerivation {
|
||||
pname = spec.name;
|
||||
version = spec.version;
|
||||
inherit (spec) version;
|
||||
inherit src;
|
||||
isLibrary = builtins.hasAttr "library" spec;
|
||||
isExecutable = builtins.hasAttr "executables" spec;
|
||||
|
@ -27,16 +27,17 @@ let
|
||||
fetch_git = name: spec:
|
||||
let
|
||||
ref =
|
||||
if spec ? ref then spec.ref else
|
||||
spec.ref or (
|
||||
if spec ? branch then "refs/heads/${spec.branch}" else
|
||||
if spec ? tag then "refs/tags/${spec.tag}" else
|
||||
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
|
||||
submodules = if spec ? submodules then spec.submodules else false;
|
||||
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"
|
||||
);
|
||||
submodules = spec.submodules or false;
|
||||
submoduleArg =
|
||||
let
|
||||
nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
|
||||
emptyArgWithWarning =
|
||||
if submodules == true
|
||||
if submodules
|
||||
then
|
||||
builtins.trace
|
||||
(
|
||||
@ -115,7 +116,7 @@ let
|
||||
# the path directly as opposed to the fetched source.
|
||||
replace = name: drv:
|
||||
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}";
|
||||
in
|
||||
if ersatz == "" then drv else
|
||||
@ -151,7 +152,7 @@ let
|
||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||
in
|
||||
if lessThan nixVersion "1.12" then
|
||||
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
||||
fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
|
||||
else
|
||||
fetchTarball attrs;
|
||||
|
||||
@ -161,7 +162,7 @@ let
|
||||
inherit (builtins) lessThan nixVersion fetchurl;
|
||||
in
|
||||
if lessThan nixVersion "1.12" then
|
||||
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
||||
fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
|
||||
else
|
||||
fetchurl attrs;
|
||||
|
||||
@ -182,7 +183,7 @@ let
|
||||
# The "config" used by the fetchers
|
||||
mkConfig =
|
||||
{ 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
|
||||
, pkgs ? mkPkgs sources system
|
||||
}: rec {
|
||||
|
@ -179,6 +179,7 @@ data SourcesNixVersion
|
||||
| -- Support submodules for git repos
|
||||
V27
|
||||
| -- formatting fix
|
||||
-- Apply statix suggestions
|
||||
V28
|
||||
deriving stock (Bounded, Enum, Eq)
|
||||
|
||||
@ -252,7 +253,7 @@ sourcesVersionToMD5 = \case
|
||||
V25 -> "6612caee5814670e5e4d9dd1b71b5f70"
|
||||
V26 -> "937bff93370a064c9000f13cec5867f9"
|
||||
V27 -> "8031ba9d8fbbc7401c800d0b84278ec8"
|
||||
V28 -> "2ed0d91d652b28d99f14659144a0af28"
|
||||
V28 -> "26ed55356db7673935329210a4f8c4a5"
|
||||
|
||||
-- | The MD5 sum of ./nix/sources.nix
|
||||
sourcesNixMD5 :: IO T.Text
|
||||
|
Loading…
Reference in New Issue
Block a user