Skip to content

Commit

Permalink
more fixes, add exeName
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Oct 4, 2023
1 parent 13e56f4 commit a0c3b76
Show file tree
Hide file tree
Showing 4 changed files with 533 additions and 151 deletions.
13 changes: 7 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
outputs = inputs: let
inherit (builtins) fromJSON readFile fetchClosure attrValues;
inherit (import ./lib.nix) filterAttrs symlinkPath sane mapAndMergeAttrs aggregate;
inherit (import ./lib.nix) filterAttrs symlinkPath sane mapAndMergeAttrs aggregate optionalAttr;

# This is a really verbose name, but it ensures we don't get collisions
nameOf = pkg: sane "${pkg.meta.name or pkg.meta.pname}-${pkg.org_name}-${pkg.repo_name}-${pkg.version}";
Expand All @@ -11,11 +11,12 @@
packages =
mapAndMergeAttrs (
flakeUrl: pkg: {
packages.${pkg.system}.${nameOf pkg} = symlinkPath {
inherit (pkg) pname version meta system;
name = pkg.meta.name;
path = fetchClosure pkg.closure;
};
packages.${pkg.system}.${nameOf pkg} = symlinkPath ({
inherit (pkg) pname version meta system;
name = pkg.meta.name;
path = fetchClosure pkg.closure;
}
// (optionalAttr pkg "exeName"));
}
)
validPackages;
Expand Down
23 changes: 21 additions & 2 deletions lib.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
let
inherit (builtins) attrNames concatMap elemAt fetchClosure foldl' head isAttrs length listToAttrs replaceStrings zipAttrsWith;
inherit
(builtins)
attrNames
concatMap
elemAt
fetchClosure
foldl'
hasAttr
head
isAttrs
length
listToAttrs
replaceStrings
zipAttrsWith
;

# x86-64-linux
busybox = fetchClosure {
Expand Down Expand Up @@ -80,6 +94,11 @@ let
recursiveUpdateUntil (path: lhs: rhs: !(isAttrs lhs && isAttrs rhs)) lhs rhs;

mapAndMergeAttrs = f: attrs: foldl' recursiveUpdate {} (mapAttrsToList f attrs);

optionalAttr = attrs: name:
if hasAttr name attrs
then {${name} = attrs.${name};}
else {};
in {
inherit filterAttrs mapAndMergeAttrs sane symlinkPath aggregate;
inherit filterAttrs mapAndMergeAttrs sane symlinkPath aggregate optionalAttr;
}
33 changes: 17 additions & 16 deletions packages.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Config
end

config = Config.new.parse
pp! config

def sh(command : String, *args : String)
output = IO::Memory.new
Expand Down Expand Up @@ -75,8 +74,6 @@ def fetch_git_refs(org_name, repo_name, ref_patterns, dest)
end
end

pp! org_name, repo_name, ref_patterns, refs_tags

puts "writing #{dest}"
File.write(dest, refs_tags.to_h.to_pretty_json)
end
Expand Down Expand Up @@ -172,6 +169,7 @@ struct Package
property closure : NamedTuple(fromPath: String, toPath: String, fromStore: String)?
property pname : String?
property system : String
property exeName : String?

def initialize(@config, @system, @name, @version, @commit, @org_name, @repo_name)
end
Expand Down Expand Up @@ -209,6 +207,7 @@ struct Package
pname = d.pname or d.name or null;
version = d.version or null;
meta = d.meta or null;
exeName = d.exeName or null;
}
CODE

Expand All @@ -222,7 +221,8 @@ struct Package
) do |stdout|
@meta = stdout["meta"].as_h
@pname = stdout["pname"].as_s
# @version = stdout["version"].as_s
@exeName = stdout["exeName"].as_s?
true
end
end

Expand All @@ -245,18 +245,7 @@ struct Package
"--accept-flake-config",
"--no-write-lock-file",
) do |stdout|
pp! stdout
end
end

def nix_copy_closure
process(copy_closure_file_path, false,
"nix", "copy", closure.not_nil![:toPath],
"--to", config.to,
"--accept-flake-config",
"--no-write-lock-file",
) do |stdout|
pp! stdout
true
end
end

Expand All @@ -274,6 +263,17 @@ struct Package
end
end

def nix_copy_closure
process(copy_closure_file_path, false,
"nix", "copy", closure.not_nil![:toPath],
"--to", config.to,
"--accept-flake-config",
"--no-write-lock-file",
) do |stdout|
true
end
end

def mkdirs
[eval_file_path, build_file_path, copy_original_file_path, copy_closure_file_path, closure_file_path].each do |path|
FileUtils.mkdir_p(File.dirname(path))
Expand Down Expand Up @@ -333,6 +333,7 @@ each_package(config) do |pkg|
pkg.nix_copy_original &&
pkg.nix_store_make_content_addressed &&
pkg.nix_copy_closure

valid[pkg.flake_url] = pkg if pkg.closure
end

Expand Down
Loading

0 comments on commit a0c3b76

Please sign in to comment.