Nix code refactor to support standard Nix and best practices

marijan
Mar 12, 2025, 4:43 PM
ZZEEGHFT2VI4UBDWNI7U2AQDYITHU2Q5MDYC5JCETMMLQFGDO5OQC

Dependencies

  • [2] NACNZRJE xxHash in oldshell.nix
  • [3] V3G26FEW Conflict resolution (flakes)
  • [4] YN63NUZO Sanakirja 1.0
  • [5] ZWPPIJXF flake.nix: use Mozilla overlay for Rust
  • [6] JEQCEOQD Adding a non-flake shell.nix
  • [7] X243Z3Y5 Recording only the required metadata (can even be changed later!)
  • [8] HYENMEQW Add nix aarch64-darwin support for Apple Silicon macs
  • [9] VKBJ6XB6 Formatting and version bump
  • [10] Q4XPH27L override dev tooling
  • [11] OP6UAT25 Fix build for darwin by providing the needed additional dependencies
  • [12] SH2ZBSAZ Fix typo in flake.nix defaultPackage
  • [13] QAXLX3UA Backwards-compatibility: moving old paths to the new "roots" feature
  • [14] BFQYATIR Add nix aarch64-darwin support for Apple Silicon macs
  • [15] WZYPQBYN flake: use crate2nix from Nixpkgs
  • [16] 2B7KNPCM flake.nix uses zstd 1.49
  • [17] STG7MO5M Version bump
  • [18] PNJL5TPZ Version bump
  • [19] LAFA7YMQ switch to oxalica/rust-overlay
  • [20] MUYNSHG2 update Nix build for Rust 2021 edition requirement
  • [21] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [22] POBHKKNG Use nixpkgs builtin Rust build tools This fixes the broken flake packages and prevents having to manually update any sort of Nix-specific lock file, which should make it less prone to breaking in the future.
  • [23] ND62U46T Get nix base builds working again
  • [24] QHVMHSGY oldshell.nix: use version 1.4.9 of ZStd because of major performance issues in 1.5
  • [25] RNNJ4ORV shell uses the flake
  • [26] JVBQMAFU Solving a conflict
  • [27] O2CDACII Solving a conflict
  • [28] G734WNM6 flake.nix: use crate2nix
  • [29] 2RUJ4J7M Bump flake.nix & flake.lock
  • [30] VN6L65VR flake.nix: remove unnecessary build inputs
  • [31] XXYMJ6PM update Rust for CVE-2022-21658
  • [*] ENWJBQGQ Fixing a deprecation warning in ed25519_dalek.

Change contents

  • replacement in shell.nix at line 1
    [4.12][4.0:341]()
    (import
    (
    let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
    fetchTarball {
    url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
    sha256 = lock.nodes.flake-compat.locked.narHash;
    }
    )
    { src = ./.; }
    ).shellNix
    [4.12]
    (import ./release.nix).pijulGitDevShell
  • file addition: release.nix (----------)
    [33.2]
    let
    flakeLock = builtins.fromJSON (builtins.readFile ./flake.lock);
    pkgsSrc = fetchTarball {
    url =
    flakeLock.nodes.nixpkgs.locked.url
    or "https://github.com/NixOS/nixpkgs/archive/${flakeLock.nodes.nixpkgs.locked.rev}.tar.gz";
    sha256 = flakeLock.nodes.nixpkgs.locked.narHash;
    };
    pkgs = import pkgsSrc {
    overlays = [
    (import ./nix/overlays/default.nix)
    (import ./nix/overlays/devshells.nix)
    ];
    };
    in
    {
    inherit (pkgs) pijul pijul-git pijulGitDevShell;
    }
  • replacement in oldshell.nix at line 1
    [4.37][4.38:64]()
    with import <nixpkgs> {};
    [4.37]
    [4.87]
    with import <nixpkgs> { };
  • replacement in oldshell.nix at line 5
    [4.104][4.104:133](),[4.133][4.212:221](),[4.221][4.142:168](),[4.806][4.142:168](),[4.142][4.142:168](),[4.168][4.115:130](),[4.130][4.182:195](),[4.182][4.182:195](),[4.195][2.0:11](),[2.11][4.195:341](),[4.195][4.195:341]()
    buildInputs = with pkgs; [
    zstd
    libsodium
    openssl
    pkg-config
    libiconv
    xxHash
    ] ++ lib.optionals stdenv.isDarwin
    (with darwin.apple_sdk.frameworks; [
    CoreServices
    Security
    SystemConfiguration
    ]);
    [4.104]
    [4.341]
    buildInputs =
    with pkgs;
    [
    zstd
    libsodium
    openssl
    pkg-config
    libiconv
    xxHash
    ]
    ++ lib.optionals stdenv.isDarwin (
    with darwin.apple_sdk.frameworks;
    [
    CoreServices
    Security
    SystemConfiguration
    ]
    );
  • file addition: nix (d--r------)
    [33.2]
  • file addition: package.nix (----------)
    [0.925]
    {
    stdenv,
    lib,
    darwin,
    rustPlatform,
    cargo,
    libiconv,
    pkg-config,
    rustc,
    openssl,
    libsodium,
    ...
    }:
    let
    cargoMeta = builtins.fromTOML (builtins.readFile ../pijul/Cargo.toml);
    inherit (rustPlatform) cargoBuildHook cargoInstallHook cargoSetupHook;
    in
    stdenv.mkDerivation {
    pname = cargoMeta.package.name;
    version = cargoMeta.package.version;
    src =
    let
    fs = lib.fileset;
    in
    fs.toSource {
    root = ../.;
    fileset = fs.unions [
    ../Cargo.toml
    ../Cargo.lock
    ../pijul-macros
    ../pijul
    ../libpijul
    ../pijul-interaction
    ../pijul-config
    ../pijul-repository
    ../pijul-identity
    ../pijul-remote
    ];
    };
    buildAndTestSubdir = "pijul";
    doCheck = true;
    cargoBuildType = "release";
    cargoDeps = rustPlatform.importCargoLock { lockFile = ../Cargo.lock; };
    nativeBuildInputs = [
    cargo
    libiconv
    pkg-config
    rustc
    ];
    buildInputs = [
    libsodium
    openssl.dev
    cargoBuildHook
    cargoInstallHook
    cargoSetupHook
    ] ++ lib.optionals (stdenv.isDarwin) [ darwin.apple_sdk.frameworks.SystemConfiguration ];
    }
  • file addition: overlays (d--r------)
    [0.925]
  • file addition: devshells.nix (----------)
    [0.2157]
    final: prev: {
    pijulGitDevShell = (final.mkShell.override { stdenv = final.clangStdenv; }) {
    name = "pijul";
    inputsFrom = [ final.pijul-git ];
    packages = with final; [
    rust-analyzer
    rustfmt
    ];
    LIBCLANG_PATH = "${final.llvmPackages.libclang}/lib";
    };
    }
  • file addition: default.nix (----------)
    [0.2157]
    final: prev: {
    pijul = final.callPackage ../package.nix { stdenv = final.clangStdenv; };
    pijul-git = final.pijul.overrideAttrs (
    oldAttrs: { cargoBuildFeatures = oldAttrs.cargoBuildFeatures or [ ] ++ [ "git" ]; }
    );
    }
  • edit in flake.nix at line 6
    [4.59][4.342:422]()
    flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
  • replacement in flake.nix at line 9
    [4.92][4.92:117](),[4.146][4.131:141](),[4.131][4.131:141](),[4.141][4.60:67]()
    { self
    , nixpkgs
    , ...
    }:
    [4.92]
    [4.1023923]
    { self, nixpkgs, ... }:
  • replacement in flake.nix at line 11
    [4.1023931][4.1023931:1024079](),[4.1024799][4.1024799:1024800](),[4.1024800][4.546:623]()
    nameValuePair = name: value: { inherit name value; };
    genAttrs = names: f: builtins.listToAttrs (map (n: nameValuePair n (f n)) names);
    LIBCLANG_PATH = "${pkgs.llvmPackages.libclang}/lib";
    }
    [4.1023931]
    [4.623]
    # there is also nixpkgs.lib.systems.flakeExposed
    allSystems = [
    "x86_64-linux"
    "aarch64-linux"
    "i686-linux"
    "x86_64-darwin"
    "aarch64-darwin"
    ];
    withPkgs =
    pkgsCallback:
    nixpkgs.lib.genAttrs allSystems (
    system:
    let
    pkgs = import nixpkgs {
    inherit system;
    overlays = [
    (import ./nix/overlays/default.nix)
    (import ./nix/overlays/devshells.nix)
    ];
    };
    in
    pkgsCallback { inherit pkgs system; }
  • replacement in flake.nix at line 34
    [4.634][4.1024849:1024850](),[4.246298][4.1024849:1024850](),[4.1024849][4.1024849:1024850](),[4.1024850][4.635:714](),[4.20][4.246504:246505](),[4.714][4.246504:246505](),[4.246504][4.246504:246505](),[4.246505][4.715:1000](),[4.1000][4.1025043:1025044](),[4.246551][4.1025043:1025044](),[4.1025043][4.1025043:1025044](),[4.1025044][4.1001:1115](),[4.1115][4.1025119:1025120](),[4.1025119][4.1025119:1025120](),[4.166][4.166:167](),[4.167][4.1314:1483]()
    packages = forAllSystems
    (pkgs: rec {
    default = pijul;
    pijul = pkgs.clangStdenv.mkDerivation (self: {
    pname = cargoMeta.package.name;
    version = cargoMeta.package.version;
    src = ./.;
    buildAndTestSubdir = "pijul";
    doCheck = true;
    cargoBuildType = "release";
    cargoDeps = pkgs.rustPlatform.importCargoLock {
    lockFile = ./Cargo.lock;
    };
    buildInputs = builtins.attrValues (
    {
    inherit (pkgs)
    libsodium
    openssl
    ;
    [4.634]
    [4.1025490]
    in
    {
    overlays = {
    default = import ./nix/overlay.nix { };
    devShells = import ./nix/devshells-overlay.nix { };
    };
    devShells = withPkgs (
    { pkgs, ... }:
    {
    default = pkgs.pijulGitDevShell;
    }
    );
  • replacement in flake.nix at line 47
    [4.1025491][4.1484:1881](),[4.1881][4.1026112:1026126](),[4.247587][4.1026112:1026126](),[4.1026112][4.1026112:1026126]()
    inherit (pkgs.rustPlatform)
    cargoBuildHook
    cargoInstallHook
    cargoSetupHook
    ;
    }
    // nixpkgs.lib.optionalAttrs (pkgs.stdenv.isDarwin) {
    inherit (pkgs.darwin.apple_sdk.frameworks)
    SystemConfiguration
    ;
    }
    );
    });
    [4.1025491]
    [4.1026126]
    formatter = withPkgs ({ pkgs, ... }: pkgs.nixfmt-rfc-style);
  • replacement in flake.nix at line 49
    [4.1026127][4.1882:2003]()
    pijul-git = pijul.overrideAttrs (self: {
    cargoBuildFeatures = [ "git" ];
    });
    });
    [4.1026127]
    [4.1026214]
    packages = withPkgs (
    { pkgs, ... }:
    {
    inherit (pkgs) pijul pijul-git;
    default = self.packages.${pkgs.system}.pijul;
    }
    );
  • edit in flake.nix at line 58
    [4.1026223][3.0:0](),[4.1025120][4.1116:1313](),[4.1313][4.1200:1215](),[4.1200][4.1200:1215](),[4.101][4.68:159](),[4.1024163][4.68:159](),[4.159][4.0:101](),[4.101][4.160:236](),[4.1024164][4.160:236](),[4.216][4.165:174](),[4.236][4.165:174](),[4.165][4.165:174](),[4.174][4.237:545](),[4.545][4.591:606](),[4.591][4.591:606]()
    nativeBuildInputs = builtins.attrValues {
    inherit (pkgs)
    cargo
    libiconv
    pkg-config
    rustc
    ;
    };
    forAllSystems = f: genAttrs allSystems (system: f nixpkgs.legacyPackages.${system});
    allSystems = [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" "aarch64-darwin" ];
    cargoMeta = builtins.fromTOML (builtins.readFile ./pijul/Cargo.toml);
    in {
    devShell = forAllSystems
    (pkgs:
    (pkgs.mkShell.override { stdenv = pkgs.clangStdenv; })
    {
    name = "pijul";
    inputsFrom = [ self.packages.${pkgs.system}.pijul-git ];
    packages = with pkgs; [
    rust-analyzer
    rustfmt
    ];
  • resolve order conflict in flake.nix at line 58
    [4.1026223]
  • edit in flake.lock at line 3
    [4.1026253][4.423:955]()
    "flake-compat": {
    "locked": {
    "lastModified": 1696426674,
    "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
    "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
    "revCount": 57,
    "type": "tarball",
    "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz"
    },
    "original": {
    "type": "tarball",
    "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
    }
    },
  • edit in flake.lock at line 21
    [4.1026722][4.1127:1167]()
    "flake-compat": "flake-compat",
  • replacement in default.nix at line 3
    [4.1172][4.1172:1242]()
    let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
    [4.1172]
    [4.1242]
    let
    lock = builtins.fromJSON (builtins.readFile ./flake.lock);
    in
  • replacement in default.nix at line 7
    [4.1261][4.1261:1408]()
    url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
    [4.1261]
    [4.1408]
    url =
    lock.nodes.flake-compat.locked.url
    or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";