1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-18 19:07:19 +03:00

Restructure Nix dirs

This commit is contained in:
Nicolas Mattia 2019-02-03 14:07:42 +01:00
parent 8d4c790464
commit 5e9d9b0695
9 changed files with 69 additions and 63 deletions

View File

@ -623,8 +623,8 @@ pathShellNix = "shell.nix"
-- | Simple shell that loads @niv@ -- | Simple shell that loads @niv@
initShellNixContent :: String initShellNixContent :: String
initShellNixContent = [s| initShellNixContent = [s|
let pkgs = import ./nix; with { pkgs = import ./nix {}; };
in pkgs.mkShell pkgs.mkShell
{ buildInputs = [ pkgs.niv ]; { buildInputs = [ pkgs.niv ];
} }
|] |]

View File

@ -1,2 +1,2 @@
with { pkgs = import ./nix {}; }; { pkgs ? import ./nix {} }:
{ inherit (pkgs) niv readme readme-test ; } pkgs.callPackage ./nix/packages.nix {}

View File

@ -1,3 +1,14 @@
{ sources ? import ./sources.nix }: { sources ? import ./sources.nix }:
import sources.nixpkgs 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 = {};
}

View File

@ -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";
}
)
]

40
nix/packages.nix Normal file
View File

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

View File

@ -1,9 +1,9 @@
# A record, from name to path, of the third-party packages # A record, from name to path, of the third-party packages
with 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 = fetchTarball =
{ url, sha256 }: { url, sha256 }:
if builtins.lessThan builtins.nixVersion "1.12" then if builtins.lessThan builtins.nixVersion "1.12" then
@ -19,11 +19,11 @@ with
mapAttrs (_: spec: mapAttrs (_: spec:
if builtins.hasAttr "outPath" spec if builtins.hasAttr "outPath" spec
then abort 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 else
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
then then
spec // spec //
{ outPath = fetchTarball { inherit (spec) url sha256; } ; } { outPath = fetchTarball { inherit (spec) url sha256; } ; }
else spec else spec
) versions ) specs

View File

@ -4,8 +4,16 @@
#!nix-shell -p nix #!nix-shell -p nix
#!nix-shell --pure #!nix-shell --pure
set -euo pipefail
export NIX_PATH="nixpkgs=./nix"
echo "Building" echo "Building"
nix build --no-link nix build --no-link
echo "Testing shell"
nix-shell --run "echo -n"
echo "all good" echo "all good"

View File

@ -1,4 +1,4 @@
with { pkgs = import ./nix; }; with { pkgs = import ./nix {}; };
pkgs.mkShell pkgs.mkShell
{ buildInputs = [ pkgs.snack-exe ]; { buildInputs = [ pkgs.snack-exe ];
} }