Skip to content

Commit

Permalink
feat: optional submodule fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
yusdacra committed Jun 13, 2021
1 parent a572026 commit f411315
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ it is converted to an attribute set equivalent to `{ root = theArg; }`.
| `src` | Used by `naersk` as source input to the derivation. When `root` is not set, `src` is also used to discover the `Cargo.toml` and `Cargo.lock`. |
| `root` | Used by `naersk` to read the `Cargo.toml` and `Cargo.lock` files. May be different from `src`. When `src` is not set, `root` is (indirectly) used as `src`. |
| `allRefs` | Whether to fetch all refs while fetching Git dependencies. Useful if the wanted revision isn't in the default branch. |
| `gitSubmodules` | Whether to fetch submodules while fetching Git dependencies. |
| `cargoBuild` | The command to use for the build. The argument must be a function modifying the default value. <br/> Default: `''cargo $cargo_options build $cargo_build_options >> $cargo_build_output_json''` |
| `cargoBuildOptions` | Options passed to cargo build, i.e. `cargo build <OPTS>`. These options can be accessed during the build through the environment variable `cargo_build_options`. <br/> Note: naersk relies on the `--out-dir out` option and the `--message-format` option. The `$cargo_message_format` variable is set based on the cargo version.<br/> Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces. <br/> The argument must be a function modifying the default value. <br/> Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' "--out-dir" "out" "--message-format=$cargo_message_format" ]` |
| `remapPathPrefix` | When `true`, rustc remaps the (`/nix/store`) source paths to `/sources` to reduce the number of dependencies in the closure. Default: `true` |
Expand Down
4 changes: 3 additions & 1 deletion config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ let
# Whether to fetch all refs while fetching Git dependencies. Useful if
# the wanted revision isn't in the default branch.
allRefs = attrs0.allRefs or false;
# Whether to fetch submodules while fetching Git dependencies.
gitSubmodules = attrs0.gitSubmodules or false;

# The command to use for the build.
cargoBuild =
Expand Down Expand Up @@ -253,7 +255,7 @@ let
# Whether we skip pre-building the deps
isSingleStep = attrs.singleStep;

inherit (attrs) overrideMain allRefs;
inherit (attrs) overrideMain allRefs gitSubmodules;

# The members we want to build
# (list of directory names)
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let
let
config = mkConfig arg;
gitDependencies =
libb.findGitDependencies { inherit (config) cargolock allRefs; };
libb.findGitDependencies { inherit (config) cargolock allRefs gitSubmodules; };
cargoconfig =
if builtinz.pathExists (toString config.root + "/.cargo/config")
then builtins.readFile (config.root + "/.cargo/config")
Expand Down
4 changes: 3 additions & 1 deletion lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ rec
# }
# ]
findGitDependencies =
{ cargolock, allRefs }:
{ cargolock, allRefs, gitSubmodules }:
let
query = p: (lib.substring 0 4 (p.source or "")) == "git+";

Expand Down Expand Up @@ -113,6 +113,8 @@ rec
ref = lock.tag;
} // lib.optionalAttrs allRefs {
allRefs = true;
} // lib.optionalAttrs gitSubmodules {
submodules = true;
});
} // lock;
in lib.foldl' (acc: e: if lib.any (oe: (oe.url == e.url) && (oe.key == e.key)) acc then acc else acc ++ [e]) [] (builtins.map mkFetch packageLocks);
Expand Down

0 comments on commit f411315

Please sign in to comment.