diff --git a/default.nix b/default.nix index f317b957..7601f57a 100644 --- a/default.nix +++ b/default.nix @@ -1,59 +1,22 @@ -{ pkgs ? import { } -, crossPkgs ? pkgs -, fenix ? import (fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz") { } -, defaultFeatures ? true -, features ? "" -}: +{ pimalaya ? import (fetchTarball "https://github.com/pimalaya/nix/archive/master.tar.gz") +, ... +} @args: -let - inherit (pkgs) binutils gnutar lib mktemp stdenv wine zip; - inherit (crossPkgs) buildPlatform hostPlatform; - - mkToolchain = import ./rust-toolchain.nix { inherit lib fenix; }; - rustTarget = if buildPlatform == hostPlatform then null else hostPlatform.rust.rustcTarget; - rustToolchain = mkToolchain.fromTarget rustTarget; - rustPlatform = crossPkgs.makeRustPlatform { - rustc = rustToolchain; - cargo = rustToolchain; - }; - - # HACK: https://github.com/NixOS/nixpkgs/issues/177129 - empty-libgcc_eh = stdenv.mkDerivation { - pname = "empty-libgcc_eh"; - version = "0"; - dontUnpack = true; - installPhase = '' - mkdir -p "$out"/lib - "${lib.getExe' binutils "ar"}" r "$out"/lib/libgcc_eh.a - ''; - }; - - himalaya = import ./package.nix { +pimalaya.mkDefault ({ + src = ./.; + version = "1.0.0"; + mkPackage = ({ lib, pkgs, rustPlatform, defaultFeatures, features }: import ./package.nix { inherit lib rustPlatform; - fetchFromGitHub = crossPkgs.fetchFromGitHub; - stdenv = crossPkgs.stdenv; - apple-sdk = if hostPlatform.isx86_64 then crossPkgs.apple-sdk_13 else crossPkgs.apple-sdk_14; - installShellFiles = crossPkgs.installShellFiles; + fetchFromGitHub = pkgs.fetchFromGitHub; + stdenv = pkgs.stdenv; + apple-sdk = if pkgs.hostPlatform.isx86_64 then pkgs.apple-sdk_13 else pkgs.apple-sdk_14; + installShellFiles = pkgs.installShellFiles; installShellCompletions = false; installManPages = false; - notmuch = crossPkgs.notmuch; - gpgme = crossPkgs.gpgme; - pkg-config = crossPkgs.pkg-config; + notmuch = pkgs.notmuch; + gpgme = pkgs.gpgme; + pkg-config = pkgs.pkg-config; buildNoDefaultFeatures = !defaultFeatures; - buildFeatures = lib.strings.splitString "," features; - }; -in - -himalaya.overrideAttrs (drv: { - version = "1.0.0"; - - propagatedBuildInputs = (drv.propagatedBuildInputs or [ ]) - ++ lib.optional hostPlatform.isWindows empty-libgcc_eh; - - src = crossPkgs.nix-gitignore.gitignoreSource [ ] ./.; - - cargoDeps = rustPlatform.importCargoLock { - lockFile = ./Cargo.lock; - allowBuiltinFetchGit = true; - }; -}) + buildFeatures = lib.splitString "," features; + }); +} // removeAttrs args [ "pimalaya" ]) diff --git a/flake.lock b/flake.lock index 170e56b2..2ae40b3d 100644 --- a/flake.lock +++ b/flake.lock @@ -36,10 +36,27 @@ "type": "github" } }, + "pimalaya": { + "flake": false, + "locked": { + "lastModified": 1732804333, + "narHash": "sha256-Umel9Au2eHcr9d9sYV6GjctBhLioEM4BBxkmiJlg/to=", + "owner": "pimalaya", + "repo": "nix", + "rev": "84e4c7c81f390abf54ac103f6f838ed68a832ee9", + "type": "github" + }, + "original": { + "owner": "pimalaya", + "repo": "nix", + "type": "github" + } + }, "root": { "inputs": { "fenix": "fenix", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pimalaya": "pimalaya" } }, "rust-analyzer-src": { diff --git a/flake.nix b/flake.nix index 2cede38e..3fbc17ca 100644 --- a/flake.nix +++ b/flake.nix @@ -2,108 +2,23 @@ description = "CLI to manage emails"; inputs = { - # TODO: nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - # + # TODO: https://github.com/NixOS/nixpkgs/pull/358989 + # nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:soywod/nixpkgs"; fenix = { - # TODO: url = "github:nix-community/fenix"; - # + # TODO: https://github.com/nix-community/fenix/pull/145 + # url = "github:nix-community/fenix"; url = "github:soywod/fenix"; inputs.nixpkgs.follows = "nixpkgs"; }; + pimalaya = { + url = "github:pimalaya/nix"; + flake = false; + }; }; - outputs = { self, nixpkgs, fenix }: - let - inherit (nixpkgs) lib; - - crossSystems = { - aarch64-darwin = [ - "aarch64-apple-darwin" - ]; - aarch64-linux = [ - "aarch64-unknown-linux-musl" - ]; - x86_64-darwin = [ - "x86_64-apple-darwin" - ]; - x86_64-linux = [ - "aarch64-unknown-linux-musl" - "armv6l-unknown-linux-musleabihf" - "armv7l-unknown-linux-musleabihf" - "i686-unknown-linux-musl" - "x86_64-unknown-linux-musl" - "x86_64-w64-mingw32" - ]; - }; - - withGitEnvs = package: package.overrideAttrs (drv: { - GIT_REV = drv.GIT_REV or self.rev or self.dirtyRev or "unknown"; - GIT_DESCRIBE = drv.GIT_DESCRIBE or "nix-flake-" + self.lastModifiedDate; - }); - - # Dev shells - - mkDevShell = system: { - default = import ./shell.nix { - pkgs = import nixpkgs { inherit system; }; - fenix = fenix.packages.${system}; - }; - }; - - # Packages - - mkPackages = system: mkCrossPackages system // { - default = withGitEnvs (import ./default.nix ({ - pkgs = import nixpkgs { inherit system; }; - fenix = fenix.packages.${system}; - })); - }; - - mkCrossPackages = system: - lib.attrsets.mergeAttrsList (map (mkCrossPackage system) crossSystems.${system}); - - mkCrossPackage = system: crossConfig: - let - pkgs = import nixpkgs { inherit system; }; - crossSystem = { config = crossConfig; isStatic = true; }; - crossPkgs = import nixpkgs { inherit system crossSystem; }; - crossPkg = import ./default.nix { inherit pkgs crossPkgs; fenix = fenix.packages.${system}; }; - in - { "cross-${crossPkgs.hostPlatform.system}" = withGitEnvs crossPkg; }; - - # Apps - - mkApps = system: mkCrossApps system // { - default = { - type = "app"; - program = lib.getExe self.packages.${system}.default; - }; - }; - - mkCrossApps = system: - lib.attrsets.mergeAttrsList (map (mkCrossApp system) crossSystems.${system}); - - mkCrossApp = system: crossConfig: - let - pkgs = import nixpkgs { inherit system; }; - mktemp = "${lib.getExe pkgs.mktemp} -d"; - emulator = crossPkgs.hostPlatform.emulator pkgs; - crossSystem = { config = crossConfig; isStatic = true; }; - crossPkgs = import nixpkgs { inherit system crossSystem; }; - crossPkgName = "cross-${crossPkgs.hostPlatform.system}"; - crossPkgExe = lib.getExe self.packages.${system}.${crossPkgName}; - program = lib.getExe (pkgs.writeShellScriptBin "himalaya" '' - ${lib.optionalString crossPkgs.hostPlatform.isWindows "export WINEPREFIX=$(${mktemp})"} - ${emulator} ${crossPkgExe} $@ - ''); - in - { "${crossPkgName}" = { inherit program; type = "app"; }; }; - in - - { - devShells = lib.genAttrs (lib.attrNames crossSystems) mkDevShell; - packages = lib.genAttrs (lib.attrNames crossSystems) mkPackages; - apps = lib.genAttrs (lib.attrNames crossSystems) mkApps; - }; + outputs = inputs: (import inputs.pimalaya).mkFlakeOutputs inputs { + shell = ./shell.nix; + default = ./default.nix; + }; } diff --git a/package.nix b/package.nix index 0f1bad26..590092e4 100644 --- a/package.nix +++ b/package.nix @@ -1,3 +1,6 @@ +# TODO: move this to nixpkgs +# This file aims to be a replacement for the nixpkgs derivation. + { lib , pkg-config , rustPlatform diff --git a/rust-toolchain.nix b/rust-toolchain.nix deleted file mode 100644 index 91ca90d4..00000000 --- a/rust-toolchain.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ lib, fenix }: - -let - file = ./rust-toolchain.toml; - sha256 = "yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk="; -in - -{ - fromFile = - let spec = { inherit file sha256; }; - in fenix.fromToolchainFile spec; - - fromTarget = target: - let - name = (lib.importTOML file).toolchain.channel; - spec = { inherit name sha256; }; - toolchain = fenix.fromToolchainName spec; - crossToolchain = fenix.targets.${target}.fromToolchainName spec; - components = [ toolchain.rustc toolchain.cargo ] - ++ lib.optional (!isNull target) crossToolchain.rust-std; - in - - fenix.combine components; -} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 965f730e..f8f7edfd 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] channel = "1.82.0" profile = "default" -components = [ "rust-src", "rust-analyzer" ] +components = ["rust-src", "rust-analyzer"] diff --git a/shell.nix b/shell.nix index a6844ca4..5dc322a9 100644 --- a/shell.nix +++ b/shell.nix @@ -1,26 +1,6 @@ -{ pkgs ? import { } -, fenix ? import (fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz") { } -, withNotmuch ? false -, withGpg ? false -, withOpenSsl ? false -}: +{ pimalaya ? import (fetchTarball "https://github.com/pimalaya/nix/archive/master.tar.gz") +, ... +} @args: -let - inherit (pkgs) lib; - mkRustToolchain = import ./rust-toolchain.nix { inherit lib fenix; }; - rust = mkRustToolchain.fromFile; -in - -pkgs.mkShell { - buildInputs = [ ] - # Nix language - ++ [ pkgs.nixd pkgs.nixpkgs-fmt ] - - # Rust - ++ [ rust ] - - # Cargo features - ++ lib.optional withNotmuch pkgs.notmuch - ++ lib.optional withGpg pkgs.gpgme - ++ lib.optional withOpenSsl pkgs.openssl; -} +pimalaya.mkShell ({ rustToolchainFile = ./rust-toolchain.toml; } + // removeAttrs args [ "pimalaya" ])