1
1
mirror of https://github.com/nmattia/niv.git synced 2024-07-08 20:16:30 +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:
builtins.path {
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
);
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;
inherit name;
path = src;
};
@ -61,7 +59,7 @@ let
};
};
niv = haskellPackages.niv;
inherit (haskellPackages) niv;
niv-sdist = pkgs.haskell.lib.sdistTarball niv;

View File

@ -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;

View File

@ -27,16 +27,17 @@ let
fetch_git = name: spec:
let
ref =
if spec ? ref then spec.ref else
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;
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 = 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 {

View File

@ -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