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

Update devshell (#367)

* Update devshell

Update nixpkgs and simplify devshell

* Run ormolu

* Fixups

* Format nix files

* Update sources
This commit is contained in:
Nicolas Mattia 2023-03-11 22:16:53 +01:00 committed by GitHub
parent 320689d737
commit de5a4e7d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 264 additions and 256 deletions

View File

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

View File

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

View File

@ -30,7 +30,8 @@ let
$ niv modify <package> -a type=tarball -a builtin=true
''
builtins_fetchTarball { inherit (spec) url sha256; };
builtins_fetchTarball
{ inherit (spec) url sha256; };
fetch_builtin-url = spec:
builtins.trace
@ -60,7 +61,8 @@ let
mkNixpkgs = sources:
if builtins.hasAttr "nixpkgs" sources
then sources.nixpkgs
else abort
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
@ -113,14 +115,17 @@ let
# Create the final "sources" from the config
mkSources = config:
mapAttrs (
mapAttrs
(
name: spec:
if builtins.hasAttr "outPath" spec
then abort
then
abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = fetch config.pkgs name spec; }
) config.sources;
)
config.sources;
# The "config" used by the fetchers
mkConfig =

View File

@ -27,7 +27,8 @@
lib.concatMap
(
exe: lib.optionals
(exe ? dependencies) exe.dependencies
(exe ? dependencies)
exe.dependencies
)
(builtins.attrValues spec.executables)
);
@ -42,7 +43,8 @@
lib.concatMap
(
test: lib.optionals
(test ? dependencies) test.dependencies
(test ? dependencies)
test.dependencies
)
(builtins.attrValues spec.tests)
);
@ -58,7 +60,8 @@
);
in
haskellPackages.callPackage (
haskellPackages.callPackage
(
{ mkDerivation }:
mkDerivation {
pname = spec.name;
@ -79,5 +82,6 @@
then lib.licenses.mit
else throw "Don't know how to handle license: ${builtins.toJSON spec.license}";
}
) {};
)
{ };
}

View File

@ -2,7 +2,6 @@
import sources.nixpkgs {
overlays = [
(_: pkgs: { inherit sources; })
(_: pkgs: { nixpkgs-fmt = import pkgs.sources.nixpkgs-fmt {}; })
(_: pkgs: { termtosvg = pkgs.callPackage ./termtosvg.nix { }; })
];
config = { };

View File

@ -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/<owner>/<repo>/archive/<rev>.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/<owner>/<repo>/archive/<rev>.tar.gz"
},
"termtosvg": {

View File

@ -167,14 +167,17 @@ let
# Create the final "sources" from the config
mkSources = config:
mapAttrs (
mapAttrs
(
name: spec:
if builtins.hasAttr "outPath" spec
then abort
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;
)
config.sources;
# The "config" used by the fetchers
mkConfig =

View File

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

View File

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

View File

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

View File

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