build(nix): update nci, fixup flake (#4537)

This commit is contained in:
Yusuf Bera Ertan 2022-11-01 03:52:03 +03:00 committed by GitHub
parent e5319ea8c5
commit 3881fef39d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 165 additions and 131 deletions

View File

@ -1,5 +1,22 @@
{ {
"nodes": { "nodes": {
"all-cabal-json": {
"flake": false,
"locked": {
"lastModified": 1665552503,
"narHash": "sha256-r14RmRSwzv5c+bWKUDaze6pXM7nOsiz1H8nvFHJvufc=",
"owner": "nix-community",
"repo": "all-cabal-json",
"rev": "d7c0434eebffb305071404edcf9d5cd99703878e",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "hackage",
"repo": "all-cabal-json",
"type": "github"
}
},
"crane": { "crane": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -19,11 +36,11 @@
"devshell": { "devshell": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1660811669, "lastModified": 1666548262,
"narHash": "sha256-V6lmsaLNFz41myppL0yxglta92ijkSvpZ+XVygAh+bU=", "narHash": "sha256-4DyN4KXqQQsCw0vCXkMThw4b5Q4/q87ZZgRb4st8COc=",
"owner": "numtide", "owner": "numtide",
"repo": "devshell", "repo": "devshell",
"rev": "c2feacb46ee69949124c835419861143c4016fb5", "rev": "c8ce8ed81726079c398f5f29c4b68a7d6a3c2fa2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -38,6 +55,7 @@
"nci", "nci",
"nixpkgs" "nixpkgs"
], ],
"all-cabal-json": "all-cabal-json",
"crane": "crane", "crane": "crane",
"devshell": [ "devshell": [
"nci", "nci",
@ -47,6 +65,7 @@
"nci", "nci",
"nixpkgs" "nixpkgs"
], ],
"ghc-utils": "ghc-utils",
"gomod2nix": [ "gomod2nix": [
"nci", "nci",
"nixpkgs" "nixpkgs"
@ -69,11 +88,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1662176993, "lastModified": 1666993587,
"narHash": "sha256-Sy7DsGAveDUFBb6YDsUSYZd/AcXfP/MOMIwMt/NgY84=", "narHash": "sha256-4cLrs+CwWnceYXnCpL5gO3bybS9CjLxUoTEKjB2QFtg=",
"owner": "nix-community", "owner": "nix-community",
"repo": "dream2nix", "repo": "dream2nix",
"rev": "809bc5940214744eb29778a9a0b03f161979c1b2", "rev": "2b7456e3d2f0053bc2474fb0c461dd468545277f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -84,11 +103,11 @@
}, },
"flake-utils": { "flake-utils": {
"locked": { "locked": {
"lastModified": 1656928814, "lastModified": 1659877975,
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -97,6 +116,22 @@
"type": "github" "type": "github"
} }
}, },
"ghc-utils": {
"flake": false,
"locked": {
"lastModified": 1662774800,
"narHash": "sha256-1Rd2eohGUw/s1tfvkepeYpg8kCEXiIot0RijapUjAkE=",
"ref": "refs/heads/master",
"rev": "bb3a2d3dc52ff0253fb9c2812bd7aa2da03e0fea",
"revCount": 1072,
"type": "git",
"url": "https://gitlab.haskell.org/bgamari/ghc-utils"
},
"original": {
"type": "git",
"url": "https://gitlab.haskell.org/bgamari/ghc-utils"
}
},
"nci": { "nci": {
"inputs": { "inputs": {
"devshell": "devshell", "devshell": "devshell",
@ -109,11 +144,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1662177071, "lastModified": 1667232647,
"narHash": "sha256-x6XF//RdZlw81tFAYM1TkjY+iQIpyMCWZ46r9o4wVQY=", "narHash": "sha256-cFo7G8BqYShgL9m7yD6p+SHAZ+aIt2guuF69LV235n8=",
"owner": "yusdacra", "owner": "yusdacra",
"repo": "nix-cargo-integration", "repo": "nix-cargo-integration",
"rev": "65270dea87bb82fc02102a15221677eea237680e", "rev": "16082f7b4e42ce140a562fa630bcf8e96eadeb59",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -124,11 +159,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1662019588, "lastModified": 1667142599,
"narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=", "narHash": "sha256-OLJxsg9VqfKjFkerOxWtNIkibsCvxsv5A8wNWO1MeWk=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2da64a81275b68fdad38af669afeda43d401e94b", "rev": "412b9917cea092f3d39f9cd5dead4effd5bc4053",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -153,11 +188,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1662087605, "lastModified": 1667184938,
"narHash": "sha256-Gpf2gp2JenKGf+TylX/YJpttY2bzsnvAMLdLaxoZRyU=", "narHash": "sha256-/kuCiXuAxiD0c0zrfDvJ1Yba3FuVdRk/ROfb393AeX4=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "60c2cfaa8b90ed8cebd18b214fac8682dcf222dd", "rev": "8f81faec35508647ced65c44fd3e8648a5518afb",
"type": "github" "type": "github"
}, },
"original": { "original": {

225
flake.nix
View File

@ -21,57 +21,124 @@
... ...
}: let }: let
lib = nixpkgs.lib; lib = nixpkgs.lib;
ncl = nci.lib.nci-lib;
mkRootPath = rel: mkRootPath = rel:
builtins.path { builtins.path {
path = "${toString ./.}/${rel}"; path = "${toString ./.}/${rel}";
name = rel; name = rel;
}; };
filteredSource = let
pathsToIgnore = [
".envrc"
".ignore"
".github"
"runtime"
"screenshot.png"
"book"
"contrib"
"docs"
"README.md"
"CHANGELOG.md"
"shell.nix"
"default.nix"
"grammars.nix"
"flake.nix"
"flake.lock"
];
ignorePaths = path: type: let
# split the nix store path into its components
components = lib.splitString "/" path;
# drop off the `/nix/hash-source` section from the path
relPathComponents = lib.drop 4 components;
# reassemble the path components
relPath = lib.concatStringsSep "/" relPathComponents;
in
lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
in
builtins.path {
name = "helix-source";
path = toString ./.;
# filter out unnecessary paths
filter = ignorePaths;
};
outputs = nci.lib.makeOutputs { outputs = nci.lib.makeOutputs {
root = ./.; root = ./.;
renameOutputs = {"helix-term" = "helix";}; config = common: {
# Set default app to hx (binary is from helix-term release build) outputs = {
# Set default package to helix-term release build # rename helix-term to helix since it's our main package
defaultOutputs = { rename = {"helix-term" = "helix";};
app = "hx"; # Set default app to hx (binary is from helix-term release build)
package = "helix"; # Set default package to helix-term release build
defaults = {
app = "hx";
package = "helix";
};
};
cCompiler.package = with common.pkgs;
if stdenv.isLinux
then gcc
else clang;
shell = {
packages = with common.pkgs;
[lld_13 cargo-flamegraph rust-analyzer]
++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin)
++ (lib.optional stdenv.isLinux lldb);
env = [
{
name = "HELIX_RUNTIME";
eval = "$PWD/runtime";
}
{
name = "RUST_BACKTRACE";
value = "1";
}
{
name = "RUSTFLAGS";
value =
if common.pkgs.stdenv.isLinux
then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
else "";
}
];
};
}; };
overrides = { pkgConfig = common: {
cCompiler = common: helix-term = {
with common.pkgs; # Wrap helix with runtime
if stdenv.isLinux wrapper = _: old: let
then gcc inherit (common) pkgs;
else clang; makeOverridableHelix = old: config: let
crateOverrides = common: _: { grammars = pkgs.callPackage ./grammars.nix config;
helix-term = prev: { runtimeDir = pkgs.runCommand "helix-runtime" {} ''
src = builtins.path { mkdir -p $out
name = "helix-source"; ln -s ${mkRootPath "runtime"}/* $out
path = toString ./.; rm -r $out/grammars
# filter out unneeded stuff that cause rebuilds ln -s ${grammars} $out/grammars
filter = path: type: '';
lib.all helix-wrapped =
(n: builtins.baseNameOf path != n) common.internal.pkgsSet.utils.wrapDerivation old
[ {
".envrc" nativeBuildInputs = [pkgs.makeWrapper];
".ignore" makeWrapperArgs = config.makeWrapperArgs or [];
".github" }
"runtime" ''
"screenshot.png" rm -rf $out/bin
"book" mkdir -p $out/bin
"contrib" ln -sf ${old}/bin/* $out/bin/
"docs" wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
"README.md" '';
"shell.nix" in
"default.nix" helix-wrapped
"grammars.nix" // {override = makeOverridableHelix old;};
"flake.nix" in
"flake.lock" makeOverridableHelix old {};
]; overrides.fix-build.overrideAttrs = prev: {
}; src = filteredSource;
# disable fetching and building of tree-sitter grammars in the helix-term build.rs # disable fetching and building of tree-sitter grammars in the helix-term build.rs
HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib]; buildInputs = ncl.addBuildInputs prev [common.config.cCompiler.package.cc.lib];
# link languages and theme toml files since helix-term expects them (for tests) # link languages and theme toml files since helix-term expects them (for tests)
preConfigure = '' preConfigure = ''
@ -87,88 +154,20 @@
meta.mainProgram = "hx"; meta.mainProgram = "hx";
}; };
}; };
shell = common: prev: {
packages =
prev.packages
++ (
with common.pkgs;
[lld_13 cargo-flamegraph rust-analyzer]
++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin)
++ (lib.optional stdenv.isLinux lldb)
);
env =
prev.env
++ [
{
name = "HELIX_RUNTIME";
eval = "$PWD/runtime";
}
{
name = "RUST_BACKTRACE";
value = "1";
}
{
name = "RUSTFLAGS";
value =
if common.pkgs.stdenv.isLinux
then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
else "";
}
];
};
}; };
}; };
makeOverridableHelix = system: old: config: let
pkgs = nixpkgs.legacyPackages.${system};
grammars = pkgs.callPackage ./grammars.nix config;
runtimeDir = pkgs.runCommand "helix-runtime" {} ''
mkdir -p $out
ln -s ${mkRootPath "runtime"}/* $out
rm -r $out/grammars
ln -s ${grammars} $out/grammars
'';
helix-wrapped =
pkgs.runCommand "${old.name}-wrapped"
{
inherit (old) pname version meta;
nativeBuildInputs = [pkgs.makeWrapper];
makeWrapperArgs = config.makeWrapperArgs or [];
}
''
mkdir -p $out
cp -r --no-preserve=mode,ownership ${old}/* $out/
chmod +x $out/bin/*
wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
'';
in
helix-wrapped
// {override = makeOverridableHelix system old;};
in in
outputs outputs
// { // {
apps =
lib.mapAttrs
(
system: apps: rec {
default = hx;
hx = {
type = "app";
program = lib.getExe self.${system}.packages.helix;
};
}
)
outputs.apps;
packages = packages =
lib.mapAttrs lib.mapAttrs
( (
system: packages: rec { system: packages:
default = helix; packages
helix = makeOverridableHelix system helix-unwrapped {}; // {
helix-debug = makeOverridableHelix system helix-unwrapped-debug {}; helix-unwrapped = packages.helix.passthru.unwrapped;
helix-unwrapped = packages.helix; helix-unwrapped-debug = packages.helix-debug.passthru.unwrapped;
helix-unwrapped-debug = packages.helix-debug; }
}
) )
outputs.packages; outputs.packages;
}; };