From de5a4e7d0184b6a852a6f23917d6f57b9622e796 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Sat, 11 Mar 2023 22:16:53 +0100 Subject: [PATCH] Update devshell (#367) * Update devshell Update nixpkgs and simplify devshell * Run ormolu * Fixups * Format nix files * Update sources --- README.md | 5 + default.nix | 23 ++-- examples/cpp-libosmium/default.nix | 48 ++++---- examples/cpp-libosmium/nix/sources.nix | 57 +++++----- examples/cpp-libosmium/overlay.nix | 2 +- foo/default.nix | 146 +++++++++++++------------ nix/default.nix | 5 +- nix/sources.json | 18 +-- nix/sources.nix | 107 +++++++++--------- script/fmt | 2 +- shell.nix | 2 +- src/Niv/Cli.hs | 14 +-- src/Niv/Git/Cmd.hs | 9 +- src/Niv/GitHub/API.hs | 22 ++-- src/Niv/Sources.hs | 32 +++--- tests/eval/default.nix | 4 +- tests/git/default.nix | 6 +- tests/github/default.nix | 18 +-- 18 files changed, 264 insertions(+), 256 deletions(-) diff --git a/README.md b/README.md index e463988..7d3b99b 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,7 @@ Usage: niv add PACKAGE [-n|--name NAME] (-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) | (-v|--version VERSION) | (-t|--template URL) | (-T|--type TYPE)] + Add a GitHub dependency Available options: @@ -287,6 +288,7 @@ Usage: niv update [PACKAGE (-o|--owner OWNER) | (-r|--rev REV) | (-v|--version VERSION) | (-t|--template URL) | (-T|--type TYPE)]] + Update dependencies Available options: @@ -319,6 +321,7 @@ Usage: niv modify PACKAGE [-n|--name NAME] (-b|--branch BRANCH) | (-o|--owner OWNER) | (-r|--rev REV) | (-v|--version VERSION) | (-t|--template URL) | (-T|--type TYPE)] + Modify dependency attributes without performing an update Available options: @@ -348,6 +351,7 @@ Examples: niv drop my-package version Usage: niv drop PACKAGE [ATTRIBUTE] + Drop dependency Available options: @@ -360,6 +364,7 @@ Available options: Usage: niv init [--fast | --latest | --nixpkgs OWNER/REPO (-b|--nixpkgs-branch ARG) | --no-nixpkgs] + Initialize a Nix project. Existing files won't be modified. Available options: diff --git a/default.nix b/default.nix index d1e41d7..73765e9 100644 --- a/default.nix +++ b/default.nix @@ -3,7 +3,7 @@ }: let - files = pkgs.callPackage ./nix/files.nix {}; + files = pkgs.callPackage ./nix/files.nix { }; sourceByRegex = name: src: regexes: builtins.path { @@ -13,7 +13,7 @@ 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; @@ -69,10 +69,10 @@ let let niv-version = niv.version; in - pkgs.writeShellScript "cabal-upload" - '' - cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz" - ''; + pkgs.writeShellScript "cabal-upload" + '' + cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz" + ''; # WARNING: extremely disgusting hack below. # @@ -147,11 +147,8 @@ let # version from `package.yaml` and create a dummy module that we inject in the # `ghci` command. niv-devshell = haskellPackages.shellFor { - buildInputs = [ - pkgs.nixpkgs-fmt - pkgs.haskellPackages.ormolu - ]; packages = ps: [ ps.niv ]; + buildInputs = [ pkgs.ormolu pkgs.glibcLocales ]; shellHook = '' repl_for() { haskell_version=$(jq <./package.yaml -cMr '.version' | sed 's/\./,/g') @@ -196,7 +193,7 @@ rec tests-github = pkgs.callPackage ./tests/github { inherit niv; }; tests-git = pkgs.callPackage ./tests/git { inherit niv; }; - tests-eval = pkgs.callPackage ./tests/eval {}; + tests-eval = pkgs.callPackage ./tests/eval { }; fmt-check = pkgs.stdenv.mkDerivation @@ -245,7 +242,7 @@ rec echo done ''; - readme-test = pkgs.runCommand "README-test" {} + readme-test = pkgs.runCommand "README-test" { } '' err() { echo @@ -258,7 +255,7 @@ rec diff ${./README.md} ${readme} && echo dummy > $out || err ; ''; - niv-svg-test = pkgs.runCommand "niv-svg-test" {} + niv-svg-test = pkgs.runCommand "niv-svg-test" { } '' # XXX: This test means that the svg needs to be regenerated # by hand on (virtually) every commit. diff --git a/examples/cpp-libosmium/default.nix b/examples/cpp-libosmium/default.nix index b11a756..af2f01c 100644 --- a/examples/cpp-libosmium/default.nix +++ b/examples/cpp-libosmium/default.nix @@ -7,31 +7,31 @@ let ]; }; in - with pkgs; +with pkgs; - stdenv.mkDerivation { - name = "nix-cpp-demo"; - nativeBuildInputs = [ cmake pkgconfig ]; - src = pkgs.lib.cleanSource ./.; +stdenv.mkDerivation { + name = "nix-cpp-demo"; + nativeBuildInputs = [ cmake pkgconfig ]; + src = pkgs.lib.cleanSource ./.; - # tell Cmake location of all headers - cmakeFlags = [ - "-DEXTERNAL_INCLUDE_DIRECTORIES=${lib.strings.makeSearchPathOutput "dev" "include" libosmium.buildInputs}" - ]; + # tell Cmake location of all headers + cmakeFlags = [ + "-DEXTERNAL_INCLUDE_DIRECTORIES=${lib.strings.makeSearchPathOutput "dev" "include" libosmium.buildInputs}" + ]; - buildInputs = lib.lists.concatLists [ - # We want to check if dependencies exist using find_package - [ - libosmium.buildInputs - ] - # dependencies - [ - libosmium - ] - ]; + buildInputs = lib.lists.concatLists [ + # We want to check if dependencies exist using find_package + [ + libosmium.buildInputs + ] + # dependencies + [ + libosmium + ] + ]; - installPhase = '' - mkdir -p $out/bin - cp bin/hello-world $out/bin - ''; - } + installPhase = '' + mkdir -p $out/bin + cp bin/hello-world $out/bin + ''; +} diff --git a/examples/cpp-libosmium/nix/sources.nix b/examples/cpp-libosmium/nix/sources.nix index 6e2bf23..8f261e4 100644 --- a/examples/cpp-libosmium/nix/sources.nix +++ b/examples/cpp-libosmium/nix/sources.nix @@ -30,7 +30,8 @@ let $ niv modify -a type=tarball -a builtin=true '' - builtins_fetchTarball { inherit (spec) url sha256; }; + builtins_fetchTarball + { inherit (spec) url sha256; }; fetch_builtin-url = spec: builtins.trace @@ -52,19 +53,20 @@ let if hasNixpkgsPath then if hasThisAsNixpkgsPath - then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {} - else import {} + then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) { } + else import { } else - import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {}; + import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) { }; mkNixpkgs = sources: 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. - ''; + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; hasNixpkgsPath = (builtins.tryEval ).success; hasThisAsNixpkgsPath = @@ -96,31 +98,34 @@ let let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball { inherit url; } - else - fetchTarball attrs; + 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; + if lessThan nixVersion "1.12" then + fetchurl { inherit url; } + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = fetch config.pkgs name spec; } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = fetch config.pkgs name spec; } + ) + config.sources; # The "config" used by the fetchers mkConfig = @@ -135,4 +140,4 @@ let inherit pkgs; }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/examples/cpp-libosmium/overlay.nix b/examples/cpp-libosmium/overlay.nix index 67b28bc..6e4fa7e 100644 --- a/examples/cpp-libosmium/overlay.nix +++ b/examples/cpp-libosmium/overlay.nix @@ -1,3 +1,3 @@ self: super: { - libosmium = self.callPackage ./overlay/libosmium.nix {}; + libosmium = self.callPackage ./overlay/libosmium.nix { }; } diff --git a/foo/default.nix b/foo/default.nix index 14dd656..a51218f 100644 --- a/foo/default.nix +++ b/foo/default.nix @@ -6,78 +6,82 @@ { buildPackage = attrs: - let - src = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.src else attrs; - root = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.root else attrs; - nubdeps = ds: lib.lists.sort (x: y: x < y) ( - lib.unique ( - map (d: lib.head (lib.splitString " " d)) ds + let + src = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.src else attrs; + root = if !lib.isDerivation attrs && lib.isAttrs attrs then attrs.root else attrs; + nubdeps = ds: lib.lists.sort (x: y: x < y) ( + lib.unique ( + map (d: lib.head (lib.splitString " " d)) ds + ) + ); + spec = builtins.fromJSON (builtins.readFile (root + "/package.yaml")); + commonDeps = spec.dependencies; + + libraryExtraDeps = + lib.optionals + (spec ? library && spec.library ? dependencies) + spec.library.dependencies; + libraryDeps = nubdeps (commonDeps ++ libraryExtraDeps); + + exeExtraDeps = lib.optionals (spec ? executables) ( + lib.concatMap + ( + exe: lib.optionals + (exe ? dependencies) + exe.dependencies ) - ); - spec = builtins.fromJSON (builtins.readFile (root + "/package.yaml")); - commonDeps = spec.dependencies; - - libraryExtraDeps = - lib.optionals - (spec ? library && spec.library ? dependencies) - spec.library.dependencies; - libraryDeps = nubdeps (commonDeps ++ libraryExtraDeps); - - exeExtraDeps = lib.optionals (spec ? executables) ( - lib.concatMap - ( - exe: lib.optionals - (exe ? dependencies) exe.dependencies - ) - (builtins.attrValues spec.executables) - ); - exeDeps = - nubdeps - ( - builtins.filter (x: x != spec.name) - (commonDeps ++ exeExtraDeps) - ); - - testExtraDeps = lib.optionals (spec ? tests) ( - lib.concatMap - ( - test: lib.optionals - (test ? dependencies) test.dependencies - ) - (builtins.attrValues spec.tests) - ); - testDeps = nubdeps (builtins.filter (x: x != spec.name) (commonDeps ++ testExtraDeps)); - - depsFor = depType: - map ( - d: - if ! builtins.hasAttr d haskellPackages - then throw "haskellPackages does not contain dependency '${d}' needed for '${depType}'" - else - haskellPackages.${d} + (builtins.attrValues spec.executables) + ); + exeDeps = + nubdeps + ( + builtins.filter (x: x != spec.name) + (commonDeps ++ exeExtraDeps) ); - in - haskellPackages.callPackage ( - { mkDerivation }: - mkDerivation { - pname = spec.name; - version = spec.version; - inherit src; - isLibrary = builtins.hasAttr "library" spec; - isExecutable = builtins.hasAttr "executables" spec; - enableSeparateDataOutput = true; - libraryHaskellDepends = depsFor "libraryHaskellDepends" libraryDeps; - libraryToolDepends = [ haskellPackages.hpack ]; - executableHaskellDepends = depsFor "executableHaskellDepends" exeDeps; - testHaskellDepends = depsFor "testHaskellDepends" testDeps; - prePatch = "hpack"; - homepage = "https://github.com/${spec.github}#readme"; - description = spec.synopsis; - license = - if builtins.hasAttr "license" spec && spec.license == "MIT" - then lib.licenses.mit - else throw "Don't know how to handle license: ${builtins.toJSON spec.license}"; - } - ) {}; + testExtraDeps = lib.optionals (spec ? tests) ( + lib.concatMap + ( + test: lib.optionals + (test ? dependencies) + test.dependencies + ) + (builtins.attrValues spec.tests) + ); + testDeps = nubdeps (builtins.filter (x: x != spec.name) (commonDeps ++ testExtraDeps)); + + depsFor = depType: + map ( + d: + if ! builtins.hasAttr d haskellPackages + then throw "haskellPackages does not contain dependency '${d}' needed for '${depType}'" + else + haskellPackages.${d} + ); + + in + haskellPackages.callPackage + ( + { mkDerivation }: + mkDerivation { + pname = spec.name; + version = spec.version; + inherit src; + isLibrary = builtins.hasAttr "library" spec; + isExecutable = builtins.hasAttr "executables" spec; + enableSeparateDataOutput = true; + libraryHaskellDepends = depsFor "libraryHaskellDepends" libraryDeps; + libraryToolDepends = [ haskellPackages.hpack ]; + executableHaskellDepends = depsFor "executableHaskellDepends" exeDeps; + testHaskellDepends = depsFor "testHaskellDepends" testDeps; + prePatch = "hpack"; + homepage = "https://github.com/${spec.github}#readme"; + description = spec.synopsis; + license = + if builtins.hasAttr "license" spec && spec.license == "MIT" + then lib.licenses.mit + else throw "Don't know how to handle license: ${builtins.toJSON spec.license}"; + } + ) + { }; } diff --git a/nix/default.nix b/nix/default.nix index 1dc3516..f2d8a73 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -2,8 +2,7 @@ import sources.nixpkgs { overlays = [ (_: pkgs: { inherit sources; }) - (_: pkgs: { nixpkgs-fmt = import pkgs.sources.nixpkgs-fmt {}; }) - (_: pkgs: { termtosvg = pkgs.callPackage ./termtosvg.nix {}; }) + (_: pkgs: { termtosvg = pkgs.callPackage ./termtosvg.nix { }; }) ]; - config = {}; + config = { }; } diff --git a/nix/sources.json b/nix/sources.json index 48d6478..e141539 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,22 +5,10 @@ "homepage": null, "owner": "NixOS", "repo": "nixpkgs", - "rev": "6844c91781fdad8ad523b77ec9d1f35ff407a8e6", - "sha256": "199d0g2i3aph2c7sjkngr722l9yqzk40b7wr6dklnx4pxssgwbrp", + "rev": "5d6d90c3bf3d95902427c64dae883715de1fae19", + "sha256": "027l7f1533wb8cb55dq11dfvkpi48s5m15cq3aj0f84m715682vn", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/6844c91781fdad8ad523b77ec9d1f35ff407a8e6.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs-fmt": { - "branch": "master", - "description": "Nix code formatter for nixpkgs [maintainer=@zimbatm]", - "homepage": "https://nix-community.github.io/nixpkgs-fmt/", - "owner": "nix-community", - "repo": "nixpkgs-fmt", - "rev": "2a64f4b6a597d0d62004ffcec3ae4fd83cd1efc8", - "sha256": "01kx4y1d4c5fjvpcffk92pk9hdbgg5j9h2ryqy2hfm54s7mb0k63", - "type": "tarball", - "url": "https://github.com/nix-community/nixpkgs-fmt/archive/2a64f4b6a597d0d62004ffcec3ae4fd83cd1efc8.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/5d6d90c3bf3d95902427c64dae883715de1fae19.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "termtosvg": { diff --git a/nix/sources.nix b/nix/sources.nix index 9a01c8a..23ab29b 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -10,27 +10,27 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; 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`!"; + 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; submoduleArg = let @@ -44,15 +44,15 @@ let + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + "does not support them" ) - {} - else {}; + { } + else { }; in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -86,16 +86,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -118,10 +118,10 @@ let saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -132,7 +132,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -143,43 +143,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # 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 isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -191,4 +194,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/script/fmt b/script/fmt index 7ef63c7..cc4aa7f 100755 --- a/script/fmt +++ b/script/fmt @@ -30,7 +30,7 @@ fmt() { for f in $(find . -name '*.hs') do echo "checking: $f" - if ! ormolu --mode "$mode" "$f"; then + if ! ormolu --no-cabal --mode "$mode" "$f"; then needs_formatting+=( "$f" ) fi done diff --git a/shell.nix b/shell.nix index 4d49dae..24cd09c 100644 --- a/shell.nix +++ b/shell.nix @@ -1,2 +1,2 @@ -{ pkgs ? import ./nix {} }: +{ pkgs ? import ./nix { } }: (import ./default.nix { inherit pkgs; }).niv-devshell diff --git a/src/Niv/Cli.hs b/src/Niv/Cli.hs index 7abd5db..55efcf8 100644 --- a/src/Niv/Cli.hs +++ b/src/Niv/Cli.hs @@ -164,13 +164,13 @@ parseNixpkgs = parseNixpkgsFast <|> parseNixpkgsLatest <|> parseNixpkgsCustom <| <> Opts.metavar "OWNER/REPO" ) ) - <*> ( Opts.strOption - ( Opts.long "nixpkgs-branch" - <> Opts.short 'b' - <> Opts.help "The nixpkgs branch when using --nixpkgs ...." - <> Opts.showDefault - ) - ) + <*> ( Opts.strOption + ( Opts.long "nixpkgs-branch" + <> Opts.short 'b' + <> Opts.help "The nixpkgs branch when using --nixpkgs ...." + <> Opts.showDefault + ) + ) parseNoNixpkgs = Opts.flag' NoNixpkgs diff --git a/src/Niv/Git/Cmd.hs b/src/Niv/Git/Cmd.hs index d6338c0..c4c1f27 100644 --- a/src/Niv/Git/Cmd.hs +++ b/src/Niv/Git/Cmd.hs @@ -67,9 +67,12 @@ parseGitShortcut txt'@(T.dropWhileEnd (== '/') -> txt) = else Nothing where isGitURL = - ".git" `T.isSuffixOf` txt - || "git@" `T.isPrefixOf` txt - || "ssh://" `T.isPrefixOf` txt + ".git" + `T.isSuffixOf` txt + || "git@" + `T.isPrefixOf` txt + || "ssh://" + `T.isPrefixOf` txt parseGitPackageSpec :: Opts.Parser PackageSpec parseGitPackageSpec = diff --git a/src/Niv/GitHub/API.hs b/src/Niv/GitHub/API.hs index bc51fc3..0700789 100644 --- a/src/Niv/GitHub/API.hs +++ b/src/Niv/GitHub/API.hs @@ -80,17 +80,17 @@ defaultRequest :: [T.Text] -> IO HTTP.Request defaultRequest (map T.encodeUtf8 -> parts) = do let path = T.encodeUtf8 githubPath <> BS8.intercalate "/" (parts) mtoken <- lookupEnv' "GITHUB_TOKEN" - pure $ - ( flip (maybe id) mtoken $ \token -> - HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token) - ) - $ HTTP.setRequestPath path $ - HTTP.addRequestHeader "user-agent" "niv" $ - HTTP.addRequestHeader "accept" "application/vnd.github.v3+json" $ - HTTP.setRequestSecure githubSecure $ - HTTP.setRequestHost (T.encodeUtf8 githubApiHost) $ - HTTP.setRequestPort githubApiPort $ - HTTP.defaultRequest + pure + $ ( flip (maybe id) mtoken $ \token -> + HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token) + ) + $ HTTP.setRequestPath path + $ HTTP.addRequestHeader "user-agent" "niv" + $ HTTP.addRequestHeader "accept" "application/vnd.github.v3+json" + $ HTTP.setRequestSecure githubSecure + $ HTTP.setRequestHost (T.encodeUtf8 githubApiHost) + $ HTTP.setRequestPort githubApiPort + $ HTTP.defaultRequest -- | Get the latest revision for owner, repo and branch. -- TODO: explain no error handling diff --git a/src/Niv/Sources.hs b/src/Niv/Sources.hs index 0de41b0..ff8b75f 100644 --- a/src/Niv/Sources.hs +++ b/src/Niv/Sources.hs @@ -178,6 +178,8 @@ data SourcesNixVersion V26 | -- Support submodules for git repos V27 + | -- formatting fix + V28 deriving stock (Bounded, Enum, Eq) -- | A user friendly version @@ -210,6 +212,7 @@ sourcesVersionToText = \case V25 -> "25" V26 -> "26" V27 -> "27" + V28 -> "28" latestVersionMD5 :: T.Text latestVersionMD5 = sourcesVersionToMD5 maxBound @@ -249,6 +252,7 @@ sourcesVersionToMD5 = \case V25 -> "6612caee5814670e5e4d9dd1b71b5f70" V26 -> "937bff93370a064c9000f13cec5867f9" V27 -> "8031ba9d8fbbc7401c800d0b84278ec8" + V28 -> "2ed0d91d652b28d99f14659144a0af28" -- | The MD5 sum of ./nix/sources.nix sourcesNixMD5 :: IO T.Text @@ -276,20 +280,20 @@ warnIfOutdated = do | v == maxBound -> pure () -- The file is older than than latest | otherwise -> do - tsay $ - T.unlines - [ T.unwords - [ tbold $ tblue "INFO:", - "new sources.nix available:", - sourcesVersionToText v, - "->", - sourcesVersionToText maxBound - ], - " Please run 'niv init' or add the following line in the " - <> T.pack pathNixSourcesNix - <> " file:", - " # niv: no_update" - ] + tsay $ + T.unlines + [ T.unwords + [ tbold $ tblue "INFO:", + "new sources.nix available:", + sourcesVersionToText v, + "->", + sourcesVersionToText maxBound + ], + " Please run 'niv init' or add the following line in the " + <> T.pack pathNixSourcesNix + <> " file:", + " # niv: no_update" + ] -- | Glue code between nix and sources.json initNixSourcesNixContent :: B.ByteString diff --git a/tests/eval/default.nix b/tests/eval/default.nix index 16c8c94..8fdf7ef 100644 --- a/tests/eval/default.nix +++ b/tests/eval/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? import {} +{ pkgs ? import { } }: @@ -72,7 +72,7 @@ mkTest "niv-override-eval" '' eq "$res" "hello" '' -// mkTest "sanitize-source-name" + // mkTest "sanitize-source-name" '' file=$(mktemp -d)/foo%%.bar touch "$file" diff --git a/tests/git/default.nix b/tests/git/default.nix index 8476dab..1155511 100644 --- a/tests/git/default.nix +++ b/tests/git/default.nix @@ -3,7 +3,7 @@ # TODO: this doesn' test anything meaningful yet because "niv git PACKAGE" # doesn't parse yet pkgs.runCommand "git-test" - { nativeBuildInputs = [ pkgs.git niv pkgs.nix pkgs.jq ]; } +{ nativeBuildInputs = [ pkgs.git niv pkgs.nix pkgs.jq ]; } ( # make sure the tests run smoothly in multi-user install @@ -35,8 +35,8 @@ pkgs.runCommand "git-test" git checkout master popd > /dev/null '' + # Then we `niv add` that repo and check some properties, like the revision - # and revCount, to make sure it was imported properly, and that sources.nix - # does what it's supposed to do. + # and revCount, to make sure it was imported properly, and that sources.nix + # does what it's supposed to do. '' nivdir=$(mktemp -d) pushd $nivdir > /dev/null diff --git a/tests/github/default.nix b/tests/github/default.nix index ab83b76..d8050b1 100644 --- a/tests/github/default.nix +++ b/tests/github/default.nix @@ -20,15 +20,15 @@ let nixpkgs-channels_HEAD = "571b40d3f50466d3e91c1e609d372de96d782793"; in pkgs.runCommand "test" - { - buildInputs = [ - pkgs.haskellPackages.wai-app-static - niv - pkgs.nix - pkgs.jq - pkgs.netcat-gnu - ]; - } +{ + buildInputs = [ + pkgs.haskellPackages.wai-app-static + niv + pkgs.nix + pkgs.jq + pkgs.netcat-gnu + ]; +} '' set -euo pipefail