diff --git a/docs/build.nix b/docs/build.nix index 29de9e28..1689634d 100644 --- a/docs/build.nix +++ b/docs/build.nix @@ -4,7 +4,7 @@ _: { devShells.dev-docs = pkgs.mkShell { name = "docs-env"; packages = [ pkgs.mdbook ]; - shellHook = config.pre-commit.installationScript; + shellHook = config.settings.shell.hook; }; packages.lambda-buffers-book = pkgs.stdenv.mkDerivation { diff --git a/extras/.envrc b/extras/.envrc new file mode 100644 index 00000000..c2d0c7b2 --- /dev/null +++ b/extras/.envrc @@ -0,0 +1 @@ +use flake .#dev-nix diff --git a/extras/build.nix b/extras/build.nix index 32c63c56..1d32f2d1 100644 --- a/extras/build.nix +++ b/extras/build.nix @@ -7,15 +7,17 @@ }; # Makes it available in the system agnostic `lib` argument. - config._module.args.lib = config.flake.lib // { - inherit (config) lbf-nix; - }; + config = { + _module.args.lib = config.flake.lib // { + inherit (config) lbf-nix; + }; - # Sets the above set option to system ones. - config.lbf-nix = lib.genAttrs config.systems (system: (config.perSystem system).lbf-nix); + # Sets the above set option to system ones. + lbf-nix = lib.genAttrs config.systems (system: (config.perSystem system).lbf-nix); - # Makes `lib.x86_64-linux.xyz` available - config.flake.lib = config.lbf-nix; + # Makes `lib.x86_64-linux.xyz` available + flake.lib = config.lbf-nix; + }; options = { @@ -30,6 +32,12 @@ # Sets a per system `lbf-nix` option. config = { + devShells.dev-nix = pkgs.mkShell { + name = "dev-nix"; + shellHook = config.settings.shell.hook; + buildInputs = config.settings.shell.tools; + }; + lbf-nix = { # NOTE(bladyjoker): If you need to add a function the export externally and use internally via config.lbf-nix, add it here. diff --git a/extras/flake-purescript.nix b/extras/flake-purescript.nix index 4fa9546b..29a9a97a 100644 --- a/extras/flake-purescript.nix +++ b/extras/flake-purescript.nix @@ -36,7 +36,7 @@ let }; }; - devShell = purs.devShell; + inherit (purs) devShell; }; in mkFlake pursProjOpts.projectName (pkgs.purescriptProject pursProjOpts) diff --git a/extras/flake-rust.nix b/extras/flake-rust.nix index c7c2f1ff..f9cb6e64 100644 --- a/extras/flake-rust.nix +++ b/extras/flake-rust.nix @@ -84,22 +84,26 @@ in ''; }; - packages."${crateName}-rust" = craneLib.buildPackage (commonArgs // { - inherit cargoArtifacts; - doCheck = false; - doInstallCargoArtifacts = true; - }); + packages = { + "${crateName}-rust" = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + doCheck = false; + doInstallCargoArtifacts = true; + }); - packages."${crateName}-rust-src" = vendoredSrc; + "${crateName}-rust-src" = vendoredSrc; - packages."${crateName}-rust-build-env" = buildEnv; + "${crateName}-rust-build-env" = buildEnv; + }; - checks."${crateName}-rust-test" = craneLib.cargoNextest (commonArgs // { - inherit cargoArtifacts; - nativeBuildInputs = testTools; - }); + checks = { + "${crateName}-rust-test" = craneLib.cargoNextest (commonArgs // { + inherit cargoArtifacts; + nativeBuildInputs = testTools; + }); - checks."${crateName}-rust-clippy" = craneLib.cargoClippy (commonArgs // { - inherit cargoArtifacts; - }); + "${crateName}-rust-clippy" = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + }); + }; } diff --git a/extras/flake-typescript.nix b/extras/flake-typescript.nix index 3385403c..5cc00a1d 100644 --- a/extras/flake-typescript.nix +++ b/extras/flake-typescript.nix @@ -146,7 +146,7 @@ let ''; node2nixDevelop = node2nixExprs { extraFlags = [ "--development" ]; }; - node2nixDevelopAttrs = ((import node2nixDevelop) { inherit nodejs pkgs; inherit (pkgs) system; }); + node2nixDevelopAttrs = (import node2nixDevelop) { inherit nodejs pkgs; inherit (pkgs) system; }; # Build the project (runs `npm run build`), and puts the entire output in the # nix store diff --git a/extras/haskell.nix/plutus.nix b/extras/haskell.nix/plutus.nix index 887e0285..fb6442c0 100644 --- a/extras/haskell.nix/plutus.nix +++ b/extras/haskell.nix/plutus.nix @@ -27,9 +27,11 @@ let packages = builtins.listToAttrs (builtins.map (name: { inherit name; - value.components.library.setupHaddockFlags = [ "--haddock-options=@${responseFile}" ]; - value.components.library.ghcOptions = [ "-XFlexibleContexts" "-Wwarn" "-fplugin-opt=PlutusTx.Plugin:defer-errors" ]; - value.components.library.extraSrcFiles = [ responseFile ]; + value.components.library = { + setupHaddockFlags = [ "--haddock-options=@${responseFile}" ]; + ghcOptions = [ "-XFlexibleContexts" "-Wwarn" "-fplugin-opt=PlutusTx.Plugin:defer-errors" ]; + extraSrcFiles = [ responseFile ]; + }; }) l); }; diff --git a/extras/lbf-nix/utils.nix b/extras/lbf-nix/utils.nix index 71cf9a45..f2a864e8 100644 --- a/extras/lbf-nix/utils.nix +++ b/extras/lbf-nix/utils.nix @@ -7,7 +7,7 @@ let then overrides.${name}.override val else val ) - ((builtins.mapAttrs (name: val: if attrs?${name} then attrs.${name} else val.default) overrides) // attrs); + ((builtins.mapAttrs (name: val: attrs.${name} or val.default) overrides) // attrs); # Makes a shell flag # Example: `mkFlag "foo" "bar" = "--foo='bar'"` mkFlag = key: value: "--${key}=${pkgs.lib.escapeShellArg "${value}"}"; diff --git a/extras/pre-commit-hooks-extra.nix b/extras/pre-commit-hooks-extra.nix index eb8f30c1..b5b7627d 100644 --- a/extras/pre-commit-hooks-extra.nix +++ b/extras/pre-commit-hooks-extra.nix @@ -4,8 +4,8 @@ ]; perSystem = { pkgs, ... }: let - rustfmt = pkgs.rust-bin.stable.latest.rustfmt; - deno = pkgs.deno; + inherit (pkgs.rust-bin.stable.latest) rustfmt; + inherit (pkgs) deno; in { pre-commit.settings.hooks = { diff --git a/pre-commit.nix b/pre-commit.nix index 0dcbf866..9ac7e204 100644 --- a/pre-commit.nix +++ b/pre-commit.nix @@ -3,30 +3,31 @@ ./extras/pre-commit-hooks-extra.nix inputs.proto-nix.lib.preCommitModule ]; - perSystem = { config, ... }: + perSystem = { config, pkgs, ... }: { - devShells.dev-pre-commit = config.pre-commit.devShell; - devShells.default = config.pre-commit.devShell; + devShells.default = pkgs.mkShell { + name = "dev-default"; + buildInputs = config.settings.shell.tools; + shellHook = config.settings.shell.hook; + }; pre-commit = { settings = { excludes = [ + ".*spago-packages.nix$" "lambda-buffers-codegen/data/goldens/.*" "lambda-buffers-codegen/data/lamval-cases/.*" "experimental/archive/.*" "experimental/ctl-env/autogen/.*" "experimental/plutustx-env/autogen/.*" - "experimental/ctl-env/spago-packages.nix" "lambda-buffers-frontend/data/goldens/good/work-dir/.*" - "docs/compiler-api.md" "lambda-buffers-testsuite/lbt-prelude/goldens/.*" - "runtimes/purescript/lbr-prelude/spago-packages.nix" - ".*/spago-packages.nix$" ]; hooks = { nixpkgs-fmt.enable = true; deadnix.enable = true; + statix.enable = true; cabal-fmt.enable = true; fourmolu.enable = true; shellcheck.enable = true; @@ -45,6 +46,7 @@ settings = { ormolu.cabalDefaultExtensions = true; + statix.ignore = [ "**spago-packages.nix" ]; }; }; }; diff --git a/runtimes/rust/lbr-prelude-derive/build.nix b/runtimes/rust/lbr-prelude-derive/build.nix index b6a6fcd2..6137ee12 100644 --- a/runtimes/rust/lbr-prelude-derive/build.nix +++ b/runtimes/rust/lbr-prelude-derive/build.nix @@ -4,7 +4,7 @@ rustFlake = config.lbf-nix.rustFlake { src = ./.; - crane = inputs.crane; + inherit (inputs) crane; crateName = "lbr-prelude-derive"; extraSources = [ { diff --git a/runtimes/rust/lbr-prelude/build.nix b/runtimes/rust/lbr-prelude/build.nix index 17d76e51..34cb3c26 100644 --- a/runtimes/rust/lbr-prelude/build.nix +++ b/runtimes/rust/lbr-prelude/build.nix @@ -4,7 +4,7 @@ rustFlake = config.lbf-nix.rustFlake { src = ./.; - crane = inputs.crane; + inherit (inputs) crane; crateName = "lbr-prelude"; extraSources = [ { diff --git a/runtimes/typescript/lbr-plutus/build.nix b/runtimes/typescript/lbr-plutus/build.nix index bd47ac4b..cdff1141 100644 --- a/runtimes/typescript/lbr-plutus/build.nix +++ b/runtimes/typescript/lbr-plutus/build.nix @@ -1,4 +1,4 @@ -{ ... }: +_: { perSystem = { config, ... }: let @@ -15,17 +15,15 @@ { packages = { - lbr-plutus-typescript = typescriptFlake.packages.lbr-plutus-typescript; - lbr-plutus-typescript-tgz = typescriptFlake.packages.lbr-plutus-typescript-tgz; - lbr-plutus-typescript-node2nix = typescriptFlake.packages.lbr-plutus-typescript-node2nix; + inherit (typescriptFlake.packages) lbr-plutus-typescript lbr-plutus-typescript-tgz lbr-plutus-typescript-node2nix; }; devShells = { - lbr-plutus-typescript = typescriptFlake.devShells.lbr-plutus-typescript; + inherit (typescriptFlake.devShells) lbr-plutus-typescript; }; checks = { - lbr-plutus-typescript-test = typescriptFlake.checks.lbr-plutus-typescript-test; + inherit (typescriptFlake.checks) lbr-plutus-typescript-test; }; # TODO(jaredponn): for some reason, writing the more terse `inherit` diff --git a/runtimes/typescript/lbr-prelude/build.nix b/runtimes/typescript/lbr-prelude/build.nix index 5d59b11f..3a29c93a 100644 --- a/runtimes/typescript/lbr-prelude/build.nix +++ b/runtimes/typescript/lbr-prelude/build.nix @@ -1,4 +1,4 @@ -{ ... }: +_: { perSystem = { config, ... }: let @@ -13,18 +13,16 @@ in { packages = { - lbr-prelude-typescript = typescriptFlake.packages.lbr-prelude-typescript; - lbr-prelude-typescript-tgz = typescriptFlake.packages.lbr-prelude-typescript-tgz; - lbr-prelude-typescript-node2nix = typescriptFlake.packages.lbr-prelude-typescript-node2nix; + inherit (typescriptFlake.packages) lbr-prelude-typescript lbr-prelude-typescript-tgz lbr-prelude-typescript-node2nix; }; devShells = { - lbr-prelude-typescript = typescriptFlake.devShells.lbr-prelude-typescript; + inherit (typescriptFlake.devShells) lbr-prelude-typescript; }; checks = { - lbr-prelude-typescript-test = typescriptFlake.checks.lbr-prelude-typescript-test; + inherit (typescriptFlake.checks) lbr-prelude-typescript-test; }; # TODO(jaredponn): for some reason, writing the more terse `inherit` diff --git a/settings.nix b/settings.nix index 1516990e..2f81647c 100644 --- a/settings.nix +++ b/settings.nix @@ -49,8 +49,10 @@ shell = { tools = [ + pkgs.haskellPackages.apply-refact + pkgs.nil inputs.pre-commit-hooks.outputs.packages.${system}.deadnix inputs.pre-commit-hooks.outputs.packages.${system}.nixpkgs-fmt diff --git a/testsuites/lbt-plutus/api/build.nix b/testsuites/lbt-plutus/api/build.nix index 2046396e..6409a845 100644 --- a/testsuites/lbt-plutus/api/build.nix +++ b/testsuites/lbt-plutus/api/build.nix @@ -1,30 +1,32 @@ _: { perSystem = { config, ... }: { - packages.lbf-plutus-golden-api-haskell = config.lbf-nix.lbfPlutusHaskell { - name = "lbf-plutus-golden-api"; - src = ./.; - files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; - }; + packages = { + lbf-plutus-golden-api-haskell = config.lbf-nix.lbfPlutusHaskell { + name = "lbf-plutus-golden-api"; + src = ./.; + files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; + }; - packages.lbf-plutus-golden-api-purescript = config.lbf-nix.lbfPlutusPurescript { - name = "lbf-plutus-golden-api"; - src = ./.; - files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; - }; + lbf-plutus-golden-api-purescript = config.lbf-nix.lbfPlutusPurescript { + name = "lbf-plutus-golden-api"; + src = ./.; + files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; + }; - packages.lbf-plutus-golden-api-plutarch = config.lbf-nix.lbfPlutarch { - name = "lbf-plutus-plutarch-golden-api"; - src = ./.; - files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; - }; + lbf-plutus-golden-api-plutarch = config.lbf-nix.lbfPlutarch { + name = "lbf-plutus-plutarch-golden-api"; + src = ./.; + files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; + }; - packages.lbf-plutus-golden-api-rust = config.lbf-nix.lbfPlutusRust { - name = "lbf-plutus-rust-golden-api"; - src = ./.; - files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; - }; + lbf-plutus-golden-api-rust = config.lbf-nix.lbfPlutusRust { + name = "lbf-plutus-rust-golden-api"; + src = ./.; + files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; + }; + }; }; } diff --git a/testsuites/lbt-plutus/lbt-plutus-rust/build.nix b/testsuites/lbt-plutus/lbt-plutus-rust/build.nix index 9ce23c1d..2af2acd6 100644 --- a/testsuites/lbt-plutus/lbt-plutus-rust/build.nix +++ b/testsuites/lbt-plutus/lbt-plutus-rust/build.nix @@ -4,7 +4,7 @@ let rustFlake = config.lbf-nix.rustFlake { src = ./.; - crane = inputs.crane; + inherit (inputs) crane; crateName = "lbt-plutus"; extraSources = [ diff --git a/testsuites/lbt-prelude/api/build.nix b/testsuites/lbt-prelude/api/build.nix index aa2ea87b..a011e6da 100644 --- a/testsuites/lbt-prelude/api/build.nix +++ b/testsuites/lbt-prelude/api/build.nix @@ -1,24 +1,26 @@ _: { perSystem = { config, ... }: { - packages.lbf-prelude-golden-api-haskell = config.lbf-nix.lbfPreludeHaskell { - name = "lbf-prelude-golden-api"; - src = ./.; - files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; - }; + packages = { + lbf-prelude-golden-api-haskell = config.lbf-nix.lbfPreludeHaskell { + name = "lbf-prelude-golden-api"; + src = ./.; + files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; + }; - packages.lbf-prelude-golden-api-purescript = config.lbf-nix.lbfPreludePurescript { - name = "lbf-prelude-golden-api"; - src = ./.; - files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; - }; + lbf-prelude-golden-api-purescript = config.lbf-nix.lbfPreludePurescript { + name = "lbf-prelude-golden-api"; + src = ./.; + files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; + }; - packages.lbf-prelude-golden-api-rust = config.lbf-nix.lbfPreludeRust { - name = "lbf-prelude-golden-api"; - src = ./.; - files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; - }; + lbf-prelude-golden-api-rust = config.lbf-nix.lbfPreludeRust { + name = "lbf-prelude-golden-api"; + src = ./.; + files = [ "Foo.lbf" "Foo/Bar.lbf" "Days.lbf" ]; + }; + }; }; } diff --git a/testsuites/lbt-prelude/golden/build.nix b/testsuites/lbt-prelude/golden/build.nix index 93570ba3..e06d95ed 100644 --- a/testsuites/lbt-prelude/golden/build.nix +++ b/testsuites/lbt-prelude/golden/build.nix @@ -2,7 +2,7 @@ _: { perSystem = { pkgs, config, ... }: { - devShells.dev-lbt-prelude-golden = config.devShells.dev-pre-commit; + devShells.dev-lbt-prelude-golden = config.devShells.default; packages = { lbt-prelude-golden-haskell = config.lbf-nix.haskellData { diff --git a/testsuites/lbt-prelude/lbt-prelude-rust/build.nix b/testsuites/lbt-prelude/lbt-prelude-rust/build.nix index 47d78c95..528d827b 100644 --- a/testsuites/lbt-prelude/lbt-prelude-rust/build.nix +++ b/testsuites/lbt-prelude/lbt-prelude-rust/build.nix @@ -4,7 +4,7 @@ let rustFlake = config.lbf-nix.rustFlake { src = ./.; - crane = inputs.crane; + inherit (inputs) crane; crateName = "lbt-prelude"; extraSources = [