From cccaf78059b687de77e52db6c42208e8a52dd491 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Wed, 30 Oct 2024 18:42:25 +0100 Subject: [PATCH] feat: add a devshell based on vanilla Nix Signed-off-by: Raito Bezarius --- .envrc | 1 + default.nix | 79 ++++++++++++++++++++++++++++--- flake.lock | 27 ----------- flake.nix | 115 --------------------------------------------- npins/default.nix | 80 +++++++++++++++++++++++++++++++ npins/sources.json | 11 +++++ shell.nix | 7 +-- 7 files changed, 166 insertions(+), 154 deletions(-) create mode 100644 .envrc delete mode 100644 flake.lock delete mode 100644 flake.nix create mode 100644 npins/default.nix create mode 100644 npins/sources.json diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/default.nix b/default.nix index 65f558e..74451a3 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,73 @@ -(import - (fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/0f9255e01c2351cc7d116c072cb317785dd33b33.tar.gz"; - sha256 = "0m9grvfsbwmvgwaxvdzv6cmyvjnlww004gfxjvcl806ndqaxzy4j"; - }) - { src = ./.; }).defaultNix.packages.${builtins.currentSystem} +{ sources ? import ./npins, pkgs ? import sources.nixpkgs {} }: +{ + packages = { + ofborg = pkgs.rustPlatform.buildRustPackage { + name = "ofborg"; + src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; + + nativeBuildInputs = with pkgs; [ + pkg-config + rustPackages.clippy + ]; + + buildInputs = with pkgs; [ + ] ++ 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; [ + lix + ]; + + cargoLock = { + lockFile = ./Cargo.lock; + outputHashes = { + "hubcaps-0.6.2" = "sha256-yyHOCxUsehvtYfttRY4T9TDrJhSKGpJRa/SX3Sd1TNc="; + }; + }; + }; + }; + + shell = pkgs.mkShell { + name = "ofborg-devenv"; + packages = with pkgs; [ + lix + nix-prefetch-git + rustc + cargo + clippy + rustfmt + pkg-config + ]; + + 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 + ) + ''; + + RUSTFLAGS = "-D warnings"; + RUST_BACKTRACE = "1"; + RUST_LOG = "ofborg=debug"; + NIX_PATH = "nixpkgs=${pkgs.path}"; + }; +} diff --git a/flake.lock b/flake.lock deleted file mode 100644 index ed5e17d..0000000 --- a/flake.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1720031269, - "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 2464e2c..0000000 --- a/flake.nix +++ /dev/null @@ -1,115 +0,0 @@ -{ - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - }; - - outputs = - { self - , nixpkgs - , ... - }@inputs: - let - supportedSystems = [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" "aarch64-linux" ]; - forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); - in - { - devShell = forAllSystems (system: inputs.self.devShells.${system}.default); - devShells = forAllSystems - (system: - let - pkgs = import nixpkgs { - inherit system; - }; - in - { - default = pkgs.mkShell { - 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; [ - ] ++ 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 - ) - ''; - - RUSTFLAGS = "-D warnings"; - RUST_BACKTRACE = "1"; - RUST_LOG = "ofborg=debug"; - NIX_PATH = "nixpkgs=${pkgs.path}"; - }; - }); - - packages = forAllSystems (system: - let - pkgs = import nixpkgs { - inherit system; - }; - - pkg = pkgs.rustPlatform.buildRustPackage { - name = "ofborg"; - src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; - - nativeBuildInputs = with pkgs; [ - pkg-config - pkgs.rustPackages.clippy - ]; - - buildInputs = with pkgs; [ - ] ++ 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.6.2" = "sha256-yyHOCxUsehvtYfttRY4T9TDrJhSKGpJRa/SX3Sd1TNc="; - }; - }; - }; - - in - { - default = pkg; - ofborg = pkg; - }); - - hydraJobs = { - buildRs = forAllSystems (system: self.packages.${system}.ofborg); - }; - }; -} diff --git a/npins/default.nix b/npins/default.nix new file mode 100644 index 0000000..fb04b70 --- /dev/null +++ b/npins/default.nix @@ -0,0 +1,80 @@ +# Generated by npins. Do not modify; will be overwritten regularly +let + data = builtins.fromJSON (builtins.readFile ./sources.json); + version = data.version; + + mkSource = + spec: + assert spec ? type; + let + path = + if spec.type == "Git" then + mkGitSource spec + else if spec.type == "GitRelease" then + mkGitSource spec + else if spec.type == "PyPi" then + mkPyPiSource spec + else if spec.type == "Channel" then + mkChannelSource spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = path; }; + + mkGitSource = + { + repository, + revision, + url ? null, + hash, + branch ? null, + ... + }: + assert repository ? type; + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository + # In the latter case, there we will always be an url to the tarball + if url != null then + (builtins.fetchTarball { + inherit url; + sha256 = hash; + }) + else + assert repository.type == "Git"; + let + urlToName = + url: rev: + let + matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; + in + "${if matched == null then "source" else builtins.head matched}${appendShort}"; + name = urlToName repository.url revision; + in + builtins.fetchGit { + url = repository.url; + rev = revision; + inherit name; + narHash = hash; + }; + + mkPyPiSource = + { url, hash, ... }: + builtins.fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { url, hash, ... }: + builtins.fetchTarball { + inherit url; + sha256 = hash; + }; +in +if version == 4 then + builtins.mapAttrs (_: mkSource) data.pins +else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" diff --git a/npins/sources.json b/npins/sources.json new file mode 100644 index 0000000..f11c37e --- /dev/null +++ b/npins/sources.json @@ -0,0 +1,11 @@ +{ + "pins": { + "nixpkgs": { + "type": "Channel", + "name": "nixpkgs-unstable", + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.11pre698484.30c9efeef01e/nixexprs.tar.xz", + "hash": "079c53r3wryasv3ghyi2da9ipxh1bfh2pl63yj447bilh5ghjhhz" + } + }, + "version": 4 +} \ No newline at end of file diff --git a/shell.nix b/shell.nix index 0a83ea3..a6bdf20 100644 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1 @@ -(import - (fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/0f9255e01c2351cc7d116c072cb317785dd33b33.tar.gz"; - sha256 = "0m9grvfsbwmvgwaxvdzv6cmyvjnlww004gfxjvcl806ndqaxzy4j"; - }) - { src = ./.; }).shellNix +(import ./. { }).shell