-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the ability to devour only uncached derivations of a flake #10
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7913b0d
Move devour flake to sub-directory
ipetkov 72628e1
Add top level flake which exposes the `devour-flake` script
ipetkov 16e87d6
Inherit flake.lock from repo root when evaluating the devour flake
ipetkov 0591b56
flake.lock: Update
ipetkov 4733351
Add script to build uncached derivations only
ipetkov d3968c2
Add default package which includes both scripts
ipetkov 4e51383
Handle situations where nothing is built
ipetkov cbd4968
Simplify devour flake
ipetkov 8df0c8a
Avoid glob expansion in case directory is empty
ipetkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||
systems.url = "github:nix-systems/default"; | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
flake = { }; | ||
}; | ||
outputs = inputs@{ flake-parts, systems, ... }: | ||
flake-parts.lib.mkFlake { inherit inputs; } { | ||
systems = import systems; | ||
perSystem = { self', pkgs, lib, system, ... }: { | ||
packages.default = | ||
let | ||
# Given a flake output key, how to get the buildable derivation for | ||
# any of its attr values? | ||
flakeSchema = { | ||
perSystem = { | ||
lookupFlake = k: lib.attrByPath [ k system ] { }; | ||
getDrv = { | ||
packages = _: x: [ x ]; | ||
checks = _: x: [ x ]; | ||
devShells = _: x: [ x ]; | ||
apps = _: app: [ app.program ]; | ||
legacyPackages = k: v: | ||
if k == "homeConfigurations" | ||
then | ||
lib.mapAttrsToList (_: cfg: cfg.activationPackage) v | ||
else [ ]; | ||
}; | ||
}; | ||
flake = { | ||
lookupFlake = k: lib.attrByPath [ k ] { }; | ||
getDrv = { | ||
nixosConfigurations = _: cfg: | ||
lib.optional pkgs.stdenv.isLinux cfg.config.system.build.toplevel; | ||
darwinConfigurations = _: cfg: | ||
lib.optional pkgs.stdenv.isDarwin cfg.config.system.build.toplevel; | ||
}; | ||
}; | ||
}; | ||
paths = | ||
lib.flip lib.mapAttrsToList flakeSchema (lvl: lvlSchema: | ||
lib.flip lib.mapAttrsToList lvlSchema.getDrv (kind: getDrv: | ||
lib.mapAttrsToList | ||
getDrv | ||
(lvlSchema.lookupFlake kind inputs.flake)) | ||
); | ||
in | ||
pkgs.writeText "devour-output" (lib.strings.concatLines (lib.lists.flatten paths)); | ||
}; | ||
}; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ coreutils-full | ||
, findutils | ||
, jq | ||
, nix | ||
, nix-build-uncached | ||
, writeShellApplication | ||
}: | ||
|
||
writeShellApplication { | ||
name = "devour-flake-uncached"; | ||
runtimeInputs = [ | ||
coreutils-full | ||
findutils | ||
jq | ||
nix | ||
nix-build-uncached | ||
]; | ||
text = '' | ||
set -euo pipefail | ||
|
||
FLAKE="$1" | ||
shift 1 || true | ||
|
||
outDir=$(mktemp -d devour-flake-uncached.XXXX) | ||
cleanup() { | ||
rm -rf "$outDir" | ||
} | ||
trap cleanup EXIT | ||
|
||
nix derivation show \ | ||
${../devour}#default \ | ||
"$@" \ | ||
-L \ | ||
--reference-lock-file ${../flake.lock} \ | ||
--override-input flake "$FLAKE" \ | ||
| jq -r 'to_entries[].value.inputDrvs | to_entries[].key' \ | ||
| ( | ||
cd "$outDir" | ||
1>&2 xargs nix-build-uncached | ||
find . -type l -exec readlink '{}' \; | ||
) | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't had the time to look at this (and the other) PR in detail yet, but could you aim to minimize the diff in your PRs? It would make the review easier for me. For eg., there is no need to move the code to a new
devour/flake.nix
.Refactors are good, but should happen on a PR of their own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted the actual flake itself to be usable without having to go through what's in
nixpkgs
. As it stands today the stubbedflake = {}
input makes it so it cannot be evaluated. By moving it to a separate directory the scripts can still reference it while they themselves being exposed by the actual repo flake.There wasn't a good way for me to introduce the new build script and show an end-to-end working concept. I tried to keep each of the commits small and incremental so they're easier to review that way. If you'd prefer me to split things out into multiple PRs I can do that, but the content will end up being the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Every PR should do one thing, and one thing only. Even when you are updating
flake.lock
(0591b56), that should be a PR of its own.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#12
#13
#14
#15
#16