mirror of
https://github.com/nmattia/snack.git
synced 2025-01-06 04:25:30 +03:00
Rename snack.nix -> package.nix
This commit is contained in:
parent
b44e0f9d00
commit
6904d6b4f5
10
README.md
10
README.md
@ -75,7 +75,7 @@ The _snack_ executable is now in your `PATH`:
|
||||
|
||||
``` shell
|
||||
$ snack --help
|
||||
Usage: snack [-l|--lib DIR] [-j|--cores INT] ([-s|--snack-nix PATH] |
|
||||
Usage: snack [-l|--lib DIR] [-j|--cores INT] ([-s|--package-nix PATH] |
|
||||
[-p|--package-yaml PATH]) COMMAND
|
||||
|
||||
Available options:
|
||||
@ -215,7 +215,7 @@ in
|
||||
Building and running the project is as simple as
|
||||
|
||||
``` shell
|
||||
$ snack run # looks for a file called snack.nix by default
|
||||
$ snack run # looks for a file called package.nix by default
|
||||
```
|
||||
|
||||
Alternatively, use `$ snack build` or `$ snack ghci` if you only want to build,
|
||||
@ -228,7 +228,7 @@ You may want custom builds that involve things such as [archiving and base64
|
||||
encoding entire
|
||||
directories](https://github.com/nmattia/snack/blob/c8e9e2d5ddaba2e0aa3e6c68a26bdc1063d387f3/bin/snack.nix#L10).
|
||||
|
||||
_snack_ builds itself, so its [`snack.nix`](./bin/snack.nix) is a good example
|
||||
_snack_ builds itself, so its [`package.nix`](./bin/package.nix) is a good example
|
||||
of an advanced configuration. You can also check out the [test
|
||||
folder](./tests).
|
||||
|
||||
@ -250,7 +250,7 @@ If you are hacking on the _snack_ executable, just start _snack_ in a GHCi
|
||||
session:
|
||||
|
||||
``` shell
|
||||
$ snack ghci -s ./bin/snack.nix
|
||||
$ snack ghci -s ./bin/package.nix
|
||||
Temporarily symlinking /nix/store/j1x5vkxjr2ibabddfkdih4sm4kwinfda-spec-json/spec.json to spec.json...
|
||||
done.
|
||||
Temporarily symlinking /nix/store/w42y6dzgfmli9r8kmgh8akqk6kyda31x-lib64/lib.tar.gz.b64 to lib.tar.gz.b64...
|
||||
@ -265,7 +265,7 @@ If you are hacking on the library, specify `-l/--lib` when running snack (this
|
||||
works in GHCi too):
|
||||
|
||||
``` shell
|
||||
*Main> :main ghci -l ./snack-lib/ -s ./tests/readme/snack.nix
|
||||
*Main> :main ghci -l ./snack-lib/ -s ./tests/readme/package.nix
|
||||
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
|
||||
[1 of 2] Compiling Lib ( /home/nicolas/projects/nmattia/snack/tests/readme/src/Lib.hs, interpreted )
|
||||
[2 of 2] Compiling Main ( /home/nicolas/projects/nmattia/snack/tests/readme/app/Main.hs, interpreted )
|
||||
|
42
bin/Snack.hs
42
bin/Snack.hs
@ -51,19 +51,19 @@ type Mode = Mode_ 'ConfigReady
|
||||
type ModeRaw = Mode_ 'ConfigRaw
|
||||
|
||||
data Mode_ c
|
||||
= Standalone (Config c FilePath SnackNix) -- Reads a snack.nix file
|
||||
= Standalone (Config c FilePath PackageNix) -- Reads a package.nix file
|
||||
| HPack (Config c FilePath PackageYaml) -- Reads a package.yaml
|
||||
|
||||
prepareMode :: ModeRaw -> IO Mode
|
||||
prepareMode = \case
|
||||
Standalone fp -> Standalone <$> mkSnackNix fp
|
||||
Standalone fp -> Standalone <$> mkPackageNix fp
|
||||
HPack fp -> HPack <$> mkPackageYaml fp
|
||||
|
||||
-- | Like a FilePath, but Nix friendly
|
||||
newtype SnackNix = SnackNix { unSnackNix :: FilePath }
|
||||
newtype PackageNix = PackageNix { unPackageNix :: FilePath }
|
||||
|
||||
mkSnackNix :: FilePath -> IO SnackNix
|
||||
mkSnackNix = fmap SnackNix . canonicalizePath
|
||||
mkPackageNix :: FilePath -> IO PackageNix
|
||||
mkPackageNix = fmap PackageNix . canonicalizePath
|
||||
|
||||
-- | Like a FilePath, but Nix friendly
|
||||
newtype SnackLib = SnackLib { unSnackLib :: FilePath }
|
||||
@ -158,9 +158,9 @@ parseMode :: Opts.Parser ModeRaw
|
||||
parseMode =
|
||||
(Standalone <$>
|
||||
Opts.strOption
|
||||
(Opts.long "snack-nix"
|
||||
(Opts.long "package-nix"
|
||||
<> Opts.short 's'
|
||||
<> Opts.value "./snack.nix"
|
||||
<> Opts.value "./package.nix"
|
||||
<> Opts.metavar "PATH")
|
||||
)
|
||||
<|>
|
||||
@ -317,28 +317,28 @@ nixBuild snackCfg extraNixArgs nixExpr =
|
||||
: [ argName narg , argValue narg ]
|
||||
nixCfg = snackNixCfg snackCfg
|
||||
|
||||
snackBuild :: SnackConfig -> SnackNix -> Sh BuildResult
|
||||
snackBuild snackCfg snackNix = do
|
||||
snackBuild :: SnackConfig -> PackageNix -> Sh BuildResult
|
||||
snackBuild snackCfg packageNix = do
|
||||
NixPath out <- nixBuild snackCfg
|
||||
[ NixArg
|
||||
{ argName = "snackNix"
|
||||
, argValue = T.pack $ unSnackNix snackNix
|
||||
{ argName = "packageNix"
|
||||
, argValue = T.pack $ unPackageNix packageNix
|
||||
, argType = Arg
|
||||
}
|
||||
]
|
||||
$ NixExpr "snack.inferSnackBuild snackNix"
|
||||
$ NixExpr "snack.inferSnackBuild packageNix"
|
||||
decodeOrFail =<< liftIO (BS.readFile $ T.unpack out)
|
||||
|
||||
snackGhci :: SnackConfig -> SnackNix -> Sh GhciBuild
|
||||
snackGhci snackCfg snackNix = do
|
||||
snackGhci :: SnackConfig -> PackageNix -> Sh GhciBuild
|
||||
snackGhci snackCfg packageNix = do
|
||||
NixPath out <- nixBuild snackCfg
|
||||
[ NixArg
|
||||
{ argName = "snackNix"
|
||||
, argValue = T.pack $ unSnackNix snackNix
|
||||
{ argName = "packageNix"
|
||||
, argValue = T.pack $ unPackageNix packageNix
|
||||
, argType = Arg
|
||||
}
|
||||
]
|
||||
$ NixExpr "snack.inferSnackGhci snackNix"
|
||||
$ NixExpr "snack.inferSnackGhci packageNix"
|
||||
liftIO (BS.readFile (T.unpack out)) >>= decodeOrFail >>= \case
|
||||
BuiltGhci g -> pure g
|
||||
b -> throwIO $ userError $ "Expected GHCi build, got " <> show b
|
||||
@ -370,11 +370,11 @@ snackGhciHPack snackCfg packageYaml = do
|
||||
b -> throwIO $ userError $ "Expected GHCi build, got " <> show b
|
||||
|
||||
runCommand :: SnackConfig -> Mode -> Command -> IO ()
|
||||
runCommand snackCfg (Standalone snackNix) = \case
|
||||
Build -> S.shelly $ void $ snackBuild snackCfg snackNix
|
||||
Run args -> quiet (snackBuild snackCfg snackNix) >>= runBuildResult args
|
||||
runCommand snackCfg (Standalone packageNix) = \case
|
||||
Build -> S.shelly $ void $ snackBuild snackCfg packageNix
|
||||
Run args -> quiet (snackBuild snackCfg packageNix) >>= runBuildResult args
|
||||
Ghci -> flip runExe [] =<<
|
||||
ghciExePath <$> (quiet (snackGhci snackCfg snackNix))
|
||||
ghciExePath <$> (quiet (snackGhci snackCfg packageNix))
|
||||
runCommand snackCfg (HPack packageYaml) = \case
|
||||
Build -> S.shelly $ void $ snackBuildHPack snackCfg packageYaml
|
||||
Run args ->
|
||||
|
@ -1,5 +1,5 @@
|
||||
_: pkgs: rec {
|
||||
snack-lib = pkgs.callPackage ../snack-lib/default.nix { };
|
||||
snack-exe =
|
||||
(snack-lib.buildAsExecutable (snack-lib.snackSpec ../bin/snack.nix)).out;
|
||||
(snack-lib.buildAsExecutable (snack-lib.snackSpec ../bin/package.nix)).out;
|
||||
}
|
||||
|
@ -65,12 +65,12 @@ let
|
||||
exe_path = "${drv.out}/${drv.relExePath}";
|
||||
};
|
||||
|
||||
inferSnackBuild = snackNix: mkPackage (import snackNix);
|
||||
inferSnackBuild = packageNix: mkPackage (import packageNix);
|
||||
|
||||
inferSnackGhci = snackNix: writeText "snack-ghci-json"
|
||||
inferSnackGhci = packageNix: writeText "snack-ghci-json"
|
||||
( builtins.toJSON (
|
||||
let
|
||||
pkgSpec = mkPackageSpec (import snackNix);
|
||||
pkgSpec = mkPackageSpec (import packageNix);
|
||||
drv =
|
||||
if builtins.isNull pkgSpec.packageMain
|
||||
then ghciWithModules ghcWith (libraryModSpecs pkgSpec)
|
||||
@ -102,7 +102,7 @@ let
|
||||
( builtins.toJSON (
|
||||
let
|
||||
pkgSpecs = hpackSpecs packageYaml;
|
||||
pkgSpec = mkPackageSpec (import snackNix);
|
||||
pkgSpec = mkPackageSpec (import packageNix);
|
||||
drv =
|
||||
let exeSpecs = builtins.attrValues pkgSpecs.executables;
|
||||
in
|
||||
@ -120,7 +120,7 @@ let
|
||||
}
|
||||
));
|
||||
|
||||
snackSpec = snackNix: mkPackageSpec (import snackNix);
|
||||
snackSpec = packageNix: mkPackageSpec (import packageNix);
|
||||
hpackSpecs = packageYaml:
|
||||
let
|
||||
descrs = pkgDescrsFromHPack packageYaml;
|
||||
|
@ -1,4 +1,4 @@
|
||||
{ snackNix
|
||||
{ packageNix
|
||||
, nixpkgs ? null
|
||||
}:
|
||||
let
|
||||
@ -7,7 +7,7 @@
|
||||
then import <nixpkgs> {}
|
||||
else import nixpkgs {};
|
||||
snack = pkgs.snack-lib;
|
||||
snackDef = import snackNix;
|
||||
snackDef = import packageNix;
|
||||
in
|
||||
{
|
||||
build = (snack.executable snackDef).build;
|
||||
|
@ -9,6 +9,6 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./snack.nix -l ../../snack-lib" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix -l ../../snack-lib" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -16,6 +16,6 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./snack.nix -l ../../snack-lib" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix -l ../../snack-lib" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -5,7 +5,7 @@ set -euo pipefail
|
||||
|
||||
TMP_DIR=$(mktemp -d)
|
||||
|
||||
git clone http://github.com/2mol/pboy.git $TMP_DIR
|
||||
git clone http://github.com/nmattia/pboy.git $TMP_DIR
|
||||
git -C $TMP_DIR reset --hard a2458d6984930a33a3b1972cb6d5c167d2511b06
|
||||
|
||||
snack -j4 build --package-yaml $TMP_DIR/package.yaml
|
||||
|
@ -16,6 +16,6 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./snack.nix -l ../../snack-lib" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix -l ../../snack-lib" test
|
||||
# Note: no HPack test, because HPack doesn't support multi library
|
||||
|
@ -16,6 +16,6 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack" test
|
||||
SNACK="snack -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./snack.nix -l ../../snack-lib" test
|
||||
SNACK="snack -s ./package.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix -l ../../snack-lib" test
|
||||
# Note: no HPack test, because HPack doesn't support multi library
|
||||
|
@ -16,5 +16,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -16,5 +16,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -17,5 +17,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -17,5 +17,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -9,6 +9,6 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./snack.nix -l ../../snack-lib" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix -l ../../snack-lib" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -16,5 +16,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
SNACK="snack -j4 --package-yaml ./package.yaml" test
|
||||
|
@ -3,12 +3,12 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
snack -j4 build -s code/snack.nix
|
||||
snack -j4 run -s code/snack.nix | diff golden -
|
||||
snack -j4 build -s code/package.nix
|
||||
snack -j4 run -s code/package.nix | diff golden -
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
capture_io "$TMP_FILE" main | snack -j4 -s code/snack.nix ghci
|
||||
capture_io "$TMP_FILE" main | snack -j4 -s code/package.nix ghci
|
||||
|
||||
diff golden $TMP_FILE
|
||||
rm $TMP_FILE
|
||||
|
@ -16,5 +16,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack -j4" test
|
||||
SNACK="snack -j4 -s ./snack.nix" test
|
||||
SNACK="snack -j4 -s ./package.nix" test
|
||||
# Note: no HPack test, because HPack doesn't support multi library
|
||||
|
@ -16,5 +16,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack" test
|
||||
SNACK="snack -s ./snack.nix" test
|
||||
SNACK="snack -s ./package.nix" test
|
||||
SNACK="snack --package-yaml ./package.yaml" test
|
||||
|
@ -16,5 +16,5 @@ test() {
|
||||
}
|
||||
|
||||
SNACK="snack" test
|
||||
SNACK="snack -s ./snack.nix" test
|
||||
SNACK="snack -s ./package.nix" test
|
||||
SNACK="snack --package-yaml ./package.yaml" test
|
||||
|
Loading…
Reference in New Issue
Block a user