diff --git a/default.nix b/default.nix index 0205bc89..80aeb433 100644 --- a/default.nix +++ b/default.nix @@ -1,14 +1,6 @@ -(import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - { - src = ./.; - }) -.defaultNix +(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock); +in fetchTarball { + url = + "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; +}) { src = ./.; }).defaultNix diff --git a/flake.nix b/flake.nix index aa22f439..e7128949 100644 --- a/flake.nix +++ b/flake.nix @@ -19,20 +19,11 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { - self, - nixpkgs, - emacs-overlay, - flake-compat, - rust-overlay, - flake-utils, - devshell, - }: - {} - // ( - flake-utils.lib.eachSystem ["x86_64-linux" "x86_64-darwin"] - ( - system: let + outputs = { self, nixpkgs, emacs-overlay, flake-compat, rust-overlay + , flake-utils, devshell, }: + { } // (flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] + (system: + let pkgs = import nixpkgs { inherit system; overlays = [ @@ -41,21 +32,18 @@ (import rust-overlay) devshell.overlay ]; - config = {}; + config = { }; }; in rec { - devShells.default = with pkgs; let - custom-llvmPackages = llvmPackages_latest; - in - pkgs.devshell.mkShell { + devShells.default = with pkgs; + let custom-llvmPackages = llvmPackages_latest; + in pkgs.devshell.mkShell { imports = [ ./nix/rust.nix (pkgs.devshell.importTOML ./nix/commands.toml) ]; - packages = [ - custom-llvmPackages.clang - ]; + packages = [ custom-llvmPackages.clang ]; env = [ { name = "LIBCLANG_PATH"; @@ -66,10 +54,10 @@ value = let pwd = builtins.getEnv "PWD"; key = pwd + "/nix/cachix-key.secrets"; - in - if lib.pathExists key - then lib.removeSuffix "\n" (builtins.readFile key) - else ""; + in if lib.pathExists key then + lib.removeSuffix "\n" (builtins.readFile key) + else + ""; } ]; }; @@ -87,182 +75,140 @@ defaultApp = apps.emacsWebrender; - packages = - flake-utils.lib.flattenTree - { - inherit - (pkgs) - emacsWebrender - ; - default = pkgs.emacsWebrender; - }; - - hydraJobs = { - inherit packages; + packages = flake-utils.lib.flattenTree { + inherit (pkgs) emacsWebrender; + default = pkgs.emacsWebrender; }; - } - ) - ) - // { - overlays.default = final: prev: let - #rust nightly date - emacsWebrenderSources = prev.callPackages ./nix/_sources/generated.nix {}; - emacsWebrenderSource = emacsWebrenderSources.emacs-webrender.src; - locked-date = "2022-10-24"; - in { - emacsWebrender = with prev; let - withWebrender = true; - in - ( - final.emacsGit.override - { - withImageMagick = true; - inherit (prev) imagemagick; - } - ) - .overrideAttrs - (old: let - custom-llvmPackages = prev.llvmPackages_latest; - #withGLX - rpathLibs = with xorg; - lib.optionals (stdenv.isLinux && withWebrender) [ - libX11 - libGLU - libGL - libXpm - libXext - libXxf86vm - alsaLib - libxkbcommon - wayland - libxcb - ]; - in rec { - name = "emacs-webrender-" + version; - src = emacsWebrenderSource; - version = builtins.substring 0 7 emacsWebrenderSource.rev; - # https://github.com/NixOS/nixpkgs/blob/22.11/pkgs/applications/networking/browsers/firefox/common.nix#L574 - # Firefox use this. - # guix has cargo-utils to fix checksum, won't be useful on nix though - # https://github.com/ctrlcctrlv/revendor.guile - dontFixLibtool = true; - - preConfigure = - (old.preConfigure or "") - + '' - - '' - + lib.optionalString withWebrender '' - export NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK -lxcb-render -lxcb-xfixes -lxcb-shape" - ''; - - patches = - (old.patches or []) - ++ [ - ]; - - makeFlags = - (old.makeFlags or []) - ++ [ - "CARGO_FLAGS=--offline" #nightly channel - ]; - - #custom configure Flags Setting - configureFlags = - ( - if withWebrender - then - lib.subtractLists [ - "--with-x-toolkit=gtk3" - "--with-xft" - "--with-harfbuzz" - "--with-cairo" - "--with-imagemagick" - ] - old.configureFlags - else old.configureFlags - ) - ++ [ - "--with-json" - "--with-threads" - "--with-included-regex" - "--with-compress-install" - "--with-zlib" - "--with-dumping=pdumper" - ] - ++ lib.optionals withWebrender [ - "--with-webrender" - ] - ++ lib.optionals - (stdenv.isDarwin && withWebrender) [ - "--disable-webrender-self-contained" - ] - ++ lib.optionals stdenv.isLinux [ - "--with-dbus" - ]; - - postPatch = - (old.postPatch or "") - + '' - pwd="$(type -P pwd)" - substituteInPlace Makefile.in --replace "/bin/pwd" "$pwd" - substituteInPlace lib-src/Makefile.in --replace "/bin/pwd" "$pwd" - ''; - - LIBCLANG_PATH = "${custom-llvmPackages.libclang.lib}/lib"; - RUST_BACKTRACE = "full"; - buildInputs = - (old.buildInputs or []) - ++ [ - custom-llvmPackages.clang - custom-llvmPackages.libclang - final.rust-bin.nightly."${locked-date}".default - git - ] - ++ lib.optionals withWebrender (with xorg; [ - python3 - rpathLibs - ]) - ++ lib.optionals - stdenv.isDarwin - (with darwin.apple_sdk.frameworks; - with darwin; - [ - libobjc - Security - CoreServices - Metal - Foundation - libiconv - ] - ++ lib.optionals (withWebrender && stdenv.isDarwin) [ - AppKit - CoreGraphics - CoreServices - CoreText - Foundation - OpenGL - ]); - - dontPatchShebangs = true; #straight_watch_callback.py: unsupported interpreter directive "#!/usr/bin/env -S python3 -u" - - # postFixup = - # (old.postFixup or "") - # + ( - # if withWebrender - # then - # lib.concatStringsSep "\n" [ - # (lib.optionalString stdenv.isLinux '' - # patchelf --set-rpath \ - # "$(patchelf --print-rpath "$out/bin/.emacs-29.0.60-wrapped"):${lib.makeLibraryPath rpathLibs}" \ - # "$out/bin/.emacs-29.0.60-wrapped" - # patchelf --add-needed "libfontconfig.so" "$out/bin/.emacs-29.0.60-wrapped" - # '') - # ] - # else "" - # ); - }); - }; - }; + hydraJobs = { inherit packages; }; + })) // { + overlays.default = final: prev: + let + #rust nightly date + emacsWebrenderSources = + prev.callPackages ./nix/_sources/generated.nix { }; + emacsWebrenderSource = emacsWebrenderSources.emacs-webrender.src; + locked-date = "2022-10-24"; + in { + emacsWebrender = with prev; + let withWebrender = true; + in (final.emacsGit.override { + withImageMagick = true; + inherit (prev) imagemagick; + }).overrideAttrs (old: + let + custom-llvmPackages = prev.llvmPackages_latest; + #withGLX + rpathLibs = with xorg; + lib.optionals (stdenv.isLinux && withWebrender) [ + libX11 + libGLU + libGL + libXpm + libXext + libXxf86vm + alsaLib + libxkbcommon + wayland + libxcb + ]; + in rec { + name = "emacs-webrender-" + version; + src = emacsWebrenderSource; + version = builtins.substring 0 7 emacsWebrenderSource.rev; + # https://github.com/NixOS/nixpkgs/blob/22.11/pkgs/applications/networking/browsers/firefox/common.nix#L574 + # Firefox use this. + # guix has cargo-utils to fix checksum, won't be useful on nix though + # https://github.com/ctrlcctrlv/revendor.guile + dontFixLibtool = true; + + preConfigure = (old.preConfigure or "") + "\n" + + lib.optionalString withWebrender '' + export NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK -lxcb-render -lxcb-xfixes -lxcb-shape" + ''; + + patches = (old.patches or [ ]) ++ [ ]; + + makeFlags = (old.makeFlags or [ ]) ++ [ + "CARGO_FLAGS=--offline" # nightly channel + ]; + + #custom configure Flags Setting + configureFlags = (if withWebrender then + lib.subtractLists [ + "--with-x-toolkit=gtk3" + "--with-xft" + "--with-harfbuzz" + "--with-cairo" + "--with-imagemagick" + ] old.configureFlags + else + old.configureFlags) ++ [ + "--with-json" + "--with-threads" + "--with-included-regex" + "--with-compress-install" + "--with-zlib" + "--with-dumping=pdumper" + ] ++ lib.optionals withWebrender [ "--with-webrender" ] + ++ lib.optionals (stdenv.isDarwin && withWebrender) + [ "--disable-webrender-self-contained" ] + ++ lib.optionals stdenv.isLinux [ "--with-dbus" ]; + + postPatch = (old.postPatch or "") + '' + pwd="$(type -P pwd)" + substituteInPlace Makefile.in --replace "/bin/pwd" "$pwd" + substituteInPlace lib-src/Makefile.in --replace "/bin/pwd" "$pwd" + ''; + + LIBCLANG_PATH = "${custom-llvmPackages.libclang.lib}/lib"; + RUST_BACKTRACE = "full"; + + buildInputs = (old.buildInputs or [ ]) ++ [ + custom-llvmPackages.clang + custom-llvmPackages.libclang + final.rust-bin.nightly."${locked-date}".default + git + ] ++ lib.optionals withWebrender + (with xorg; [ python3 rpathLibs ]) + ++ lib.optionals stdenv.isDarwin + (with darwin.apple_sdk.frameworks; + with darwin; + [ + libobjc + Security + CoreServices + Metal + Foundation + libiconv + ] ++ lib.optionals (withWebrender && stdenv.isDarwin) [ + AppKit + CoreGraphics + CoreServices + CoreText + Foundation + OpenGL + ]); + + dontPatchShebangs = + true; # straight_watch_callback.py: unsupported interpreter directive "#!/usr/bin/env -S python3 -u" + + # postFixup = + # (old.postFixup or "") + # + ( + # if withWebrender + # then + # lib.concatStringsSep "\n" [ + # (lib.optionalString stdenv.isLinux '' + # patchelf --set-rpath \ + # "$(patchelf --print-rpath "$out/bin/.emacs-29.0.60-wrapped"):${lib.makeLibraryPath rpathLibs}" \ + # "$out/bin/.emacs-29.0.60-wrapped" + # patchelf --add-needed "libfontconfig.so" "$out/bin/.emacs-29.0.60-wrapped" + # '') + # ] + # else "" + # ); + }); + }; + }; } diff --git a/nix/librusty_v8.nix b/nix/librusty_v8.nix index 51bd9afb..2a59178c 100644 --- a/nix/librusty_v8.nix +++ b/nix/librusty_v8.nix @@ -1,23 +1,20 @@ -{ - rust, - stdenv, - fetchurl, -}: let +{ rust, stdenv, fetchurl, }: +let arch = rust.toRustTarget stdenv.hostPlatform; fetch_librusty_v8 = args: fetchurl { name = "librusty_v8-${args.version}"; - url = "https://github.com/denoland/rusty_v8/releases/download/v${args.version}/librusty_v8_release_${arch}.a"; + url = + "https://github.com/denoland/rusty_v8/releases/download/v${args.version}/librusty_v8_release_${arch}.a"; sha256 = args.shas.${stdenv.hostPlatform.system}; - meta = {inherit (args) version;}; + meta = { inherit (args) version; }; }; -in - fetch_librusty_v8 { - version = "0.22.1"; - shas = { - x86_64-linux = "sha256-rHI5qzwmDvlIdjUCZwvl6/s2Oe6d3/V7TJwfP1AFjik="; - x86_64-darwin = "sha256-zXXL2YqgjFmuDHGReIGWVxfSS3PMND0J0qlHRV/rKs8="; - # aarch64-linux = "sha256-yeDcrxEp3qeE6/NWEc1v7VoHjlgppIOkcHTNVksXNsM="; - # aarch64-darwin = "sha256-aq2Kjn8QSDMhNg8pEbXkJCHUKmDTNnitq42SDDVyRd4="; - }; - } +in fetch_librusty_v8 { + version = "0.22.1"; + shas = { + x86_64-linux = "sha256-rHI5qzwmDvlIdjUCZwvl6/s2Oe6d3/V7TJwfP1AFjik="; + x86_64-darwin = "sha256-zXXL2YqgjFmuDHGReIGWVxfSS3PMND0J0qlHRV/rKs8="; + # aarch64-linux = "sha256-yeDcrxEp3qeE6/NWEc1v7VoHjlgppIOkcHTNVksXNsM="; + # aarch64-darwin = "sha256-aq2Kjn8QSDMhNg8pEbXkJCHUKmDTNnitq42SDDVyRd4="; + }; +} diff --git a/nix/rust.nix b/nix/rust.nix index f18c7a45..4651fa70 100644 --- a/nix/rust.nix +++ b/nix/rust.nix @@ -1,57 +1,46 @@ -{ - lib, - config, - pkgs, - ... -}: let +{ lib, config, pkgs, ... }: +let cfg = config.language.rust; date = "2022-10-24"; -in - with pkgs; - with lib; { - options.language.rust = { - rustOverlay = - mkOption { - type = types.attrs; - default = pkgs.rust-bin.nightly."${date}"; - description = "Which nightly rust version to use - check valid data from https://github.com/oxalica/rust-overlay/tree/master/manifests/nightly"; - }; +in with pkgs; +with lib; { + options.language.rust = { + rustOverlay = mkOption { + type = types.attrs; + default = pkgs.rust-bin.nightly."${date}"; + description = '' + Which nightly rust version to use + check valid data from https://github.com/oxalica/rust-overlay/tree/master/manifests/nightly''; + }; - rustPackages = mkOption { - type = types.attrs; - default = pkgs.rustPackages; - description = "Which rust package set to use"; - }; + rustPackages = mkOption { + type = types.attrs; + default = pkgs.rustPackages; + description = "Which rust package set to use"; + }; - rustPackagesSet = - mkOption { - type = types.listOf types.str; - default = [ - ]; - description = "Which rust tools to pull from the nixpkgs channel package set - search valid packages here https://search.nixos.org/packages?channel=unstable&"; - }; + rustPackagesSet = mkOption { + type = types.listOf types.str; + default = [ ]; + description = '' + Which rust tools to pull from the nixpkgs channel package set + search valid packages here https://search.nixos.org/packages?channel=unstable&''; + }; - rustOverlaySet = - mkOption { - type = types.listOf types.str; - default = [ - "default" - "rust-analysis" - "rust-analyzer-preview" - ]; - description = "Which rust tools to pull from the rust overlay - https://github.com/oxalica/rust-overlay/blob/master/manifests/profiles.nix"; - }; + rustOverlaySet = mkOption { + type = types.listOf types.str; + default = [ "default" "rust-analysis" "rust-analyzer-preview" ]; + description = '' + Which rust tools to pull from the rust overlay + https://github.com/oxalica/rust-overlay/blob/master/manifests/profiles.nix''; }; + }; - config = { - devshell.packages = - map (tool: cfg.rustPackages.${tool}) cfg.rustPackagesSet - ++ map (tool: cfg.rustOverlay.${tool}) cfg.rustOverlaySet - ++ (with pkgs; [ + config = { + devshell.packages = map (tool: cfg.rustPackages.${tool}) cfg.rustPackagesSet + ++ map (tool: cfg.rustOverlay.${tool}) cfg.rustOverlaySet ++ (with pkgs; + [ #custom nixpkgs packages ]); - }; - } + }; +} diff --git a/shell.nix b/shell.nix index b847c560..fa2a56c7 100644 --- a/shell.nix +++ b/shell.nix @@ -1,14 +1,6 @@ -(import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - { - src = ./.; - }) -.shellNix +(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock); +in fetchTarball { + url = + "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; +}) { src = ./.; }).shellNix