diff --git a/Main.hs b/Main.hs index d9b4827..da8d8d6 100644 --- a/Main.hs +++ b/Main.hs @@ -623,8 +623,8 @@ pathShellNix = "shell.nix" -- | Simple shell that loads @niv@ initShellNixContent :: String initShellNixContent = [s| -let pkgs = import ./nix; -in pkgs.mkShell +with { pkgs = import ./nix {}; }; +pkgs.mkShell { buildInputs = [ pkgs.niv ]; } |] diff --git a/default.nix b/default.nix index 765e32e..473778c 100644 --- a/default.nix +++ b/default.nix @@ -1,2 +1,2 @@ -with { pkgs = import ./nix {}; }; -{ inherit (pkgs) niv readme readme-test ; } +{ pkgs ? import ./nix {} }: +pkgs.callPackage ./nix/packages.nix {} diff --git a/nix/default.nix b/nix/default.nix index b6c5d55..df16d2c 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,3 +1,14 @@ { sources ? import ./sources.nix }: import sources.nixpkgs - { overlays = import ./overlay.nix { inherit sources; } ; config = {}; } + { overlays = + [ + # Snack + (self: super: + { + snack-exe = (import sources.snack).snack-exe; + snack-lib = (import sources.snack).snack-lib; + } + ) + ]; + config = {}; + } diff --git a/nix/overlay.nix b/nix/overlay.nix deleted file mode 100644 index aba0b87..0000000 --- a/nix/overlay.nix +++ /dev/null @@ -1,53 +0,0 @@ -{ sources ? import ./sources.nix }: -[ - - # Snack - (self: super: - { - snack-exe = (import sources.snack).snack-exe; - snack-lib = (import sources.snack).snack-lib; - } - ) - - # Built niv - (self: super: - { niv = super.snack-lib.executable ../package.yaml ; } - ) - - # README generation - (self: super: - rec { readme = self.writeText "README.md" - (with - { template = builtins.readFile ../README.tpl.md; - niv_help = builtins.readFile - (self.runCommand "niv_help" { buildInputs = [ self.niv ]; } - "niv --help > $out" - ); - niv_add_help = builtins.readFile - (self.runCommand "niv_add_help" { buildInputs = [ self.niv ]; } - "niv add --help > $out" - ); - niv_update_help = builtins.readFile - (self.runCommand "niv_update_help" { buildInputs = [ self.niv ]; } - "niv update --help > $out" - ); - niv_drop_help = builtins.readFile - (self.runCommand "niv_drop_help" { buildInputs = [ self.niv ]; } - "niv drop --help > $out" - ); - }; - self.lib.replaceStrings - [ - "replace_niv_help" - "replace_niv_add_help" - "replace_niv_update_help" - "replace_niv_drop_help" - ] - [ niv_help niv_add_help niv_update_help niv_drop_help ] - template - ); - readme-test = self.runCommand "README-test" {} - "diff ${../README.md} ${readme} && echo dummy > $out"; - } - ) -] diff --git a/nix/packages.nix b/nix/packages.nix new file mode 100644 index 0000000..d228e5e --- /dev/null +++ b/nix/packages.nix @@ -0,0 +1,40 @@ +{ writeText +, runCommand +, lib +, snack-lib +}: +rec +{ niv = snack-lib.executable ../package.yaml; + readme = writeText "README.md" + (with + { template = builtins.readFile ../README.tpl.md; + niv_help = builtins.readFile + (runCommand "niv_help" { buildInputs = [ niv ]; } + "niv --help > $out" + ); + niv_add_help = builtins.readFile + (runCommand "niv_add_help" { buildInputs = [ niv ]; } + "niv add --help > $out" + ); + niv_update_help = builtins.readFile + (runCommand "niv_update_help" { buildInputs = [ niv ]; } + "niv update --help > $out" + ); + niv_drop_help = builtins.readFile + (runCommand "niv_drop_help" { buildInputs = [ niv ]; } + "niv drop --help > $out" + ); + }; + lib.replaceStrings + [ + "replace_niv_help" + "replace_niv_add_help" + "replace_niv_update_help" + "replace_niv_drop_help" + ] + [ niv_help niv_add_help niv_update_help niv_drop_help ] + template + ); + readme-test = runCommand "README-test" {} + "diff ${../README.md} ${readme} && echo dummy > $out"; +} diff --git a/nix/sources.nix b/nix/sources.nix index 2ae3408..184d081 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -1,9 +1,9 @@ # A record, from name to path, of the third-party packages with { - versions = builtins.fromJSON (builtins.readFile ./versions.json); + specs = builtins.fromJSON (builtins.readFile ./specs.json); - # fetchTarball version that is compatible between all the versions of Nix + # fetchTarball version that is compatible between all the specs of Nix fetchTarball = { url, sha256 }: if builtins.lessThan builtins.nixVersion "1.12" then @@ -19,11 +19,11 @@ with mapAttrs (_: spec: if builtins.hasAttr "outPath" spec then abort - "The values in versions.json should not have an 'outPath' attribute" + "The values in specs.json should not have an 'outPath' attribute" else if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec then spec // { outPath = fetchTarball { inherit (spec) url sha256; } ; } else spec - ) versions + ) specs diff --git a/nix/versions.json b/nix/specs.json similarity index 100% rename from nix/versions.json rename to nix/specs.json diff --git a/script/test b/script/test index 4c73862..2dfd93e 100755 --- a/script/test +++ b/script/test @@ -4,8 +4,16 @@ #!nix-shell -p nix #!nix-shell --pure +set -euo pipefail + +export NIX_PATH="nixpkgs=./nix" + echo "Building" nix build --no-link +echo "Testing shell" + +nix-shell --run "echo -n" + echo "all good" diff --git a/shell.nix b/shell.nix index 834168e..fa416db 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ -with { pkgs = import ./nix; }; +with { pkgs = import ./nix {}; }; pkgs.mkShell { buildInputs = [ pkgs.snack-exe ]; }