Use flake-compat for shell.nix, default.nix

This also means we can drop the entire `nix` subdirectory as well as the
`release.nix` file (since we have `hydraJobs` in our flake).
This commit is contained in:
Cole Helbling 2022-10-28 08:33:55 -07:00
parent f7b2c00dae
commit a328bf8aeb
8 changed files with 14 additions and 283 deletions

View file

@ -1,67 +1,6 @@
{ pkgs ? import ./nix {
overlays = [ (import ./nix/overlay.nix) ];
}
}:
let
inherit (pkgs) lib;
pkg = pkgs.rustPlatform.buildRustPackage {
name = "ofborg";
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
nativeBuildInputs = with pkgs; [
pkgconfig
pkgs.rustPackages.clippy
];
buildInputs = with pkgs; [
openssl
] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs; [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreFoundation
]);
preBuild = ''
cargo clippy
'';
doCheck = false; # Tests require access to a /nix/ and a nix daemon
checkInputs = with pkgs; [
nix
];
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"hubcaps-0.3.16" = "sha256-/BFXGccu27K8heK4IL7JnS/U7zatTk9wRybhtxppADM=";
};
};
};
in
{
inherit pkg;
ofborg.rs = pkgs.runCommand "ofborg-rs-symlink-compat" { src = pkg; } ''
mkdir -p $out/bin
for f in $(find $src -type f); do
bn=$(basename "$f")
ln -s "$f" "$out/bin/$bn"
# Rust 1.n? or Cargo starting outputting bins with dashes
# instead of underscores ... breaking all the callers.
if echo "$bn" | grep -q "-"; then
ln -s "$f" "$out/bin/$(echo "$bn" | tr '-' '_')"
fi
done
test -e $out/bin/builder
test -e $out/bin/github_comment_filter
test -e $out/bin/github_comment_poster
test -e $out/bin/log_message_collector
test -e $out/bin/evaluation_filter
'';
ofborg.php = import ./php { inherit pkgs; };
}
(import
(fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
})
{ src = ./.; }).defaultNix.packages.${builtins.currentSystem}

View file

@ -13,16 +13,12 @@
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
in
{
# TODO(cole-h): see if we still need these overlays
# overlays.default = import ./nix/overlay.nix;
overlays.default = _: _: { };
devShell = forAllSystems (system: inputs.self.devShells.${system}.default);
devShells = forAllSystems
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
phpEnv = pkgs.mkShell {
@ -87,7 +83,6 @@
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
pkg = pkgs.rustPlatform.buildRustPackage {
@ -124,7 +119,7 @@
};
in
rec {
{
inherit pkg;
ofborg.rs = pkgs.runCommand "ofborg-rs-symlink-compat" { src = pkg; } ''

View file

@ -1,25 +0,0 @@
let
hostpkgs = import <nixpkgs> {};
srcDef = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
inherit (hostpkgs) fetchFromGitHub fetchpatch fetchurl;
in import (hostpkgs.stdenv.mkDerivation {
name = "ofborg-nixpkgs-${builtins.substring 0 10 srcDef.rev}";
phases = [ "unpackPhase" "patchPhase" "moveToOut" ];
src = fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
inherit (srcDef) rev sha256;
};
patches = [
];
moveToOut = ''
root=$(pwd)
cd ..
mv "$root" $out
'';
})

View file

@ -1,11 +0,0 @@
{
"url": "https://github.com/nixos/nixpkgs.git",
"rev": "43b394b98e352562a6ea63db387b9fbdd858727f",
"date": "2021-11-11T14:00:02+01:00",
"path": "/nix/store/465a6kmjj22qyvhcyrjgm0azcnsm35f5-nixpkgs",
"sha256": "1r2s8hyhdlf2js1hlmgmmdkhb2bi0dyf9yil0xig5vz7g2ac2l47",
"fetchLFS": false,
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false
}

View file

@ -1,14 +0,0 @@
(self: super:
{
defaultCrateOverrides = super.defaultCrateOverrides // {
ofborg = attrs: {
buildInputs = with self.darwin.apple_sdk.frameworks;
super.lib.optional super.stdenv.isDarwin Security;
};
ofborg-simple-build = attrs: {
buildInputs = with self.darwin.apple_sdk.frameworks;
super.lib.optional super.stdenv.isDarwin Security;
};
};
})

View file

@ -1,5 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix-prefetch-git
nix-prefetch-git https://github.com/nixos/nixpkgs.git \
--rev refs/heads/nixos-unstable-small > ./nix/nixpkgs.json

View file

@ -1,83 +0,0 @@
{ nixpkgs ? ./nix
, supportedSystems ? [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]
}:
let
pkgs = import nixpkgs {
overlays = [ (import ./nix/overlay.nix) ];
};
inherit (pkgs) lib;
# An attrset of borgpkgs per supportedSystem:
#
# {
# "x86_64-linux" = ...
# "x86_64-darwin" = ...
# }
borgpkgs-per-arch = builtins.foldl'
(collector: system:
collector // {
"${system}" = import ./. {
pkgs = import nixpkgs {
inherit system;
overlays = [
(import ./nix/overlay.nix)
];
};
};
}
)
{ }
supportedSystems;
attrForSystem = system: attrpath:
if borgpkgs-per-arch ? "${system}"
then
(
let
borgpkgs = borgpkgs-per-arch."${system}";
in
if lib.hasAttrByPath attrpath borgpkgs
then
lib.setAttrByPath
(attrpath ++ [ system ])
(lib.attrByPath attrpath "bogus" borgpkgs)
else throw "Failed to find ${toString attrpath} for ${system} in borgpkgs"
)
else throw "No such system ${system}";
attrsForAllSystems = path:
builtins.foldl'
(collector: system:
lib.recursiveUpdate collector (attrForSystem system path)
)
{ }
supportedSystems;
merge = attrsets:
builtins.foldl'
(collector: set: lib.recursiveUpdate set collector)
{ }
attrsets;
x8664LinuxOnly = path:
(attrForSystem "x86_64-linux" path);
jobs = merge [
(attrsForAllSystems [ "ofborg" "rs" ])
(x8664LinuxOnly [ "ofborg" "php" ])
];
in
jobs // {
release = pkgs.releaseTools.aggregate {
name = "release";
meta.description = "Release-critical builds for OfBorg infrastructure";
constituents = [
jobs.ofborg.rs.x86_64-linux
jobs.ofborg.rs.x86_64-darwin
jobs.ofborg.rs.aarch64-darwin
jobs.ofborg.rs.aarch64-linux
jobs.ofborg.php.x86_64-linux
];
};
}

View file

@ -1,71 +1,6 @@
{ pkgs ? import ./nix {
overlays = [
(import ./nix/overlay.nix)
];
} }:
let
inherit (pkgs) stdenv lib;
phpEnv = stdenv.mkDerivation rec {
name = "gh-event-forwarder";
src = null;
buildInputs = with pkgs; [
nix-prefetch-git
php
phpPackages.composer
git
php
curl
bash
];
# HISTFILE = "${src}/.bash_hist";
};
rustEnv = stdenv.mkDerivation {
name = "gh-event-forwarder";
nativeBuildInputs = with pkgs; [
nix # so in --pure mode we actually find the "correct" nix
bash
nix-prefetch-git
rustc
cargo
clippy
rustfmt
pkg-config
git
];
buildInputs = with pkgs; [
openssl
] ++ lib.optionals stdenv.isDarwin [ darwin.Security libiconv ];
postHook = ''
checkPhase() (
cd "${builtins.toString ./.}/ofborg"
set -x
cargo fmt
git diff --exit-code
cargofmtexit=$?
cargo clippy
cargoclippyexit=$?
cargo build && cargo test
cargotestexit=$?
sum=$((cargofmtexit + cargoclippyexit + cargotestexit))
exit $sum
)
'';
HISTFILE = "${toString ./.}/.bash_hist";
RUSTFLAGS = "-D warnings";
RUST_BACKTRACE = "1";
RUST_LOG = "ofborg=debug";
NIX_PATH = "nixpkgs=${pkgs.path}";
passthru.phpEnv = phpEnv;
};
in rustEnv
(import
(fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
})
{ src = ./.; }).shellNix