diff --git a/default.nix b/default.nix index 74164e1..e72dd52 100644 --- a/default.nix +++ b/default.nix @@ -145,6 +145,7 @@ with rec # version from `package.yaml` and create a dummy module that we inject in the # `ghci` command. niv-devshell = haskellPackages.shellFor { + buildInputs = [ pkgs.nixpkgs-fmt ]; packages = ps: [ ps.niv ]; shellHook = '' repl_for() { diff --git a/nix/default.nix b/nix/default.nix index 144718e..a4d3eee 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -2,6 +2,7 @@ import sources.nixpkgs { overlays = [ (_: pkgs: { inherit sources; }) + (_: pkgs: { nixpkgs-fmt = import pkgs.sources.nixpkgs-fmt {}; }) (_: pkgs: { termtosvg = pkgs.callPackage ./termtosvg.nix {}; }) ]; config = {}; diff --git a/nix/sources.json b/nix/sources.json index a4b32f6..4204651 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -11,6 +11,18 @@ "url": "https://github.com/NixOS/nixpkgs-channels/archive/d85e435b7bded2596d7b201bcd938c94d8a921c1.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_template": "https://github.com///archive/.tar.gz" + }, "termtosvg": { "branch": "develop", "description": "Record terminal sessions as SVG animations", diff --git a/nix/sources.nix b/nix/sources.nix index 718ea6f..b53359f 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -19,7 +19,7 @@ let pkgs.fetchzip { inherit (spec) url sha256; }; fetch_git = spec: - builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; + builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; fetch_builtin-tarball = spec: builtins.trace @@ -132,5 +132,4 @@ let pkgs = mkPkgs sources; }; in -mkSources (mkConfig {}) // - { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/script/test b/script/test index cc623aa..381f293 100755 --- a/script/test +++ b/script/test @@ -2,6 +2,7 @@ #!nix-shell -i bash #!nix-shell -I nixpkgs=./nix #!nix-shell -p nix +#!nix-shell -p nixpkgs-fmt #!nix-shell --pure unset NIX_SSL_CERT_FILE @@ -32,4 +33,11 @@ fi # Build and create a root nix-build ${nixargs[@]} +echo "Formatting" +if ! nixpkgs-fmt --check . ; then + echo + echo 'run `nixpkgs-fmt .` to fix this issue' + exit 1 +fi + echo "all good" diff --git a/src/Niv/Sources.hs b/src/Niv/Sources.hs index 0180570..2c9ec14 100644 --- a/src/Niv/Sources.hs +++ b/src/Niv/Sources.hs @@ -144,6 +144,7 @@ data SourcesNixVersion | V11 | V12 | V13 + | V14 deriving stock (Bounded, Enum, Eq) -- | A user friendly version @@ -162,6 +163,7 @@ sourcesVersionToText = \case V11 -> "11" V12 -> "12" V13 -> "13" + V14 -> "14" latestVersionMD5 :: T.Text latestVersionMD5 = sourcesVersionToMD5 maxBound @@ -187,6 +189,7 @@ sourcesVersionToMD5 = \case V11 -> "8a95b7d93b16f7c7515d98f49b0ec741" V12 -> "2f9629ad9a8f181ed71d2a59b454970c" V13 -> "5e23c56b92eaade4e664cb16dcac1e0a" + V14 -> "b470e235e7bcbf106d243fea90b6cfc9" -- | The MD5 sum of ./nix/sources.nix sourcesNixMD5 :: IO T.Text diff --git a/tests/git/default.nix b/tests/git/default.nix index b1dc07f..907dd31 100644 --- a/tests/git/default.nix +++ b/tests/git/default.nix @@ -6,76 +6,72 @@ pkgs.runCommand "git-test" { nativeBuildInputs = [ pkgs.git niv pkgs.nix pkgs.jq ]; } ( - # make sure the tests run smoothly in multi-user install - # https://github.com/NixOS/nix/issues/3258 - '' - export NIX_STATE_DIR=$TMPDIR - export NIX_LOG_DIR=$TMPDIR - export HOME=$TMPDIR - '' + - # First we create a dummy git repo with one commit on master, and one commit - # on "branch". - '' - gitdir=$(mktemp -d) - pushd $gitdir > /dev/null - git init . - echo hello > file - git config user.email "niv@foo.bar" - git config user.name "Niv Niverson" - git add file - git commit -m "Initial commit" - gitrev=$(git rev-parse HEAD) + # make sure the tests run smoothly in multi-user install + # https://github.com/NixOS/nix/issues/3258 + '' + export NIX_STATE_DIR=$TMPDIR + export NIX_LOG_DIR=$TMPDIR + export HOME=$TMPDIR + '' + # First we create a dummy git repo with one commit on master, and one commit + # on "branch". + '' + gitdir=$(mktemp -d) + pushd $gitdir > /dev/null + git init . + echo hello > file + git config user.email "niv@foo.bar" + git config user.name "Niv Niverson" + git add file + git commit -m "Initial commit" + gitrev=$(git rev-parse HEAD) - git checkout -b branch - echo world >> file - git add file - git commit -m "second commit" - gitrev2=$(git rev-parse HEAD) + git checkout -b branch + echo world >> file + git add file + git commit -m "second commit" + gitrev2=$(git rev-parse HEAD) - # reset to master as "default branch" - git checkout master - popd > /dev/null - '' + + # reset to master as "default branch" + 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. + '' + nivdir=$(mktemp -d) + pushd $nivdir > /dev/null + mkdir -p nix + echo "{}" > nix/sources.json + niv init + niv add git -n my-git-repo --repo file://$gitdir + nivrev=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.rev' | jq -r) + if [ ! "$gitrev" = "$nivrev" ]; then + echo "Mismatched revs: $gitrev != $nivrev" + exit 42 + fi - # 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. - '' - nivdir=$(mktemp -d) - pushd $nivdir > /dev/null - mkdir -p nix - echo "{}" > nix/sources.json - niv init - niv add git -n my-git-repo --repo file://$gitdir - nivrev=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.rev' | jq -r) - if [ ! "$gitrev" = "$nivrev" ]; then - echo "Mismatched revs: $gitrev != $nivrev" - exit 42 - fi + # here we cheat a bit and use "outPath", which actually is the result of + # builtins.fetchGit. + nivnixrev=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.outPath.rev' | jq -r) + if [ ! "$gitrev" = "$nivnixrev" ]; then + echo "Mismatched revs: $gitrev != $nivnixrev" + exit 42 + fi + nivnixrevcount=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.outPath.revCount') + if [ ! "1" -eq "$nivnixrevcount" ]; then + echo "Mismatched revCount: 1 != $nivnixrevcount" + exit 42 + fi - # here we cheat a bit and use "outPath", which actually is the result of - # builtins.fetchGit. - nivnixrev=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.outPath.rev' | jq -r) - if [ ! "$gitrev" = "$nivnixrev" ]; then - echo "Mismatched revs: $gitrev != $nivnixrev" - exit 42 - fi - nivnixrevcount=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.outPath.revCount') - if [ ! "1" -eq "$nivnixrevcount" ]; then - echo "Mismatched revCount: 1 != $nivnixrevcount" - exit 42 - fi + niv update my-git-repo -a ref=branch + nivrev2=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.rev' | jq -r) + if [ ! "$gitrev2" = "$nivrev2" ]; then + echo "Mismatched revs: $gitrev2 != $nivrev2" + exit 42 + fi - niv update my-git-repo -a ref=branch - nivrev2=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.rev' | jq -r) - if [ ! "$gitrev2" = "$nivrev2" ]; then - echo "Mismatched revs: $gitrev2 != $nivrev2" - exit 42 - fi + popd > /dev/null - popd > /dev/null - - touch $out - '' + touch $out + '' ) -