diff options
author | Alex <alex@adnab.me> | 2022-11-29 21:26:41 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2022-11-29 21:26:41 +0000 |
commit | 448dcc5cf4685f6a321b84ba1aa38e560f63a90a (patch) | |
tree | 5318ef82fd95e007e6738cce58fd22c9f446a886 | |
parent | 280330ac72a12fbfb9c22018bb33d5a490c7a016 (diff) | |
parent | 60c26fbc628d7b450ae39214b578ab6a30583d5c (diff) | |
download | garage-448dcc5cf4685f6a321b84ba1aa38e560f63a90a.tar.gz garage-448dcc5cf4685f6a321b84ba1aa38e560f63a90a.zip |
Merge pull request 'Make repository into a Nix flake' (#424) from nix-remove-system into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/424
-rw-r--r-- | default.nix | 8 | ||||
-rw-r--r-- | flake.lock | 108 | ||||
-rw-r--r-- | flake.nix | 28 | ||||
-rw-r--r-- | nix/compile.nix | 33 | ||||
-rw-r--r-- | shell.nix | 16 |
5 files changed, 174 insertions, 19 deletions
diff --git a/default.nix b/default.nix index 60a85e2f..1791b3c6 100644 --- a/default.nix +++ b/default.nix @@ -11,14 +11,14 @@ let build_debug_and_release = (target: { debug = (compile { - inherit target git_version; + inherit system target git_version pkgsSrc cargo2nixOverlay; release = false; }).workspace.garage { compileMode = "build"; }; release = (compile { - inherit target git_version; + inherit system target git_version pkgsSrc cargo2nixOverlay; release = true; }).workspace.garage { compileMode = "build"; @@ -39,7 +39,7 @@ in { }; test = { amd64 = test (compile { - inherit git_version; + inherit system git_version pkgsSrc cargo2nixOverlay; target = "x86_64-unknown-linux-musl"; features = [ "garage/bundled-libs" @@ -52,7 +52,7 @@ in { }; clippy = { amd64 = (compile { - inherit git_version; + inherit system git_version pkgsSrc cargo2nixOverlay; target = "x86_64-unknown-linux-musl"; compiler = "clippy"; }).workspace.garage { diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..4b5713dc --- /dev/null +++ b/flake.lock @@ -0,0 +1,108 @@ +{ + "nodes": { + "cargo2nix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1666087781, + "narHash": "sha256-trKVdjMZ8mNkGfLcY5LsJJGtdV3xJDZnMVrkFjErlcs=", + "owner": "Alexis211", + "repo": "cargo2nix", + "rev": "a7a61179b66054904ef6a195d8da736eaaa06c36", + "type": "github" + }, + "original": { + "owner": "Alexis211", + "repo": "cargo2nix", + "rev": "a7a61179b66054904ef6a195d8da736eaaa06c36", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1665657542, + "narHash": "sha256-mojxNyzbvmp8NtVtxqiHGhRfjCALLfk9i/Uup68Y5q8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3073c49bc0163fea6a121c276f526837672b555", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3073c49bc0163fea6a121c276f526837672b555", + "type": "github" + } + }, + "root": { + "inputs": { + "cargo2nix": "cargo2nix", + "nixpkgs": "nixpkgs" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "cargo2nix", + "flake-utils" + ], + "nixpkgs": [ + "cargo2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1664247556, + "narHash": "sha256-J4vazHU3609ekn7dr+3wfqPo5WGlZVAgV7jfux352L0=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "524db9c9ea7bc7743bb74cdd45b6d46ea3fcc2ab", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..7d152195 --- /dev/null +++ b/flake.nix @@ -0,0 +1,28 @@ +{ + description = "Garage, an S3-compatible distributed object store for self-hosted deployments"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/a3073c49bc0163fea6a121c276f526837672b555"; + inputs.cargo2nix = { + # As of 2022-10-18: two small patches over unstable branch, one for clippy and one to fix feature detection + url = "github:Alexis211/cargo2nix/a7a61179b66054904ef6a195d8da736eaaa06c36"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, cargo2nix }: let + git_version = self.lastModifiedDate; + compile = import ./nix/compile.nix; + forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; + in + { + packages = forAllSystems (system: { + default = (compile { + inherit system git_version; + pkgsSrc = nixpkgs; + cargo2nixOverlay = cargo2nix.overlays.default; + release = true; + }).workspace.garage { + compileMode = "build"; + }; + }); + }; +} diff --git a/nix/compile.nix b/nix/compile.nix index 303c3aa4..3ea5035e 100644 --- a/nix/compile.nix +++ b/nix/compile.nix @@ -1,25 +1,32 @@ { - system ? builtins.currentSystem, - target, + system, + target ? null, + pkgsSrc, + cargo2nixOverlay, compiler ? "rustc", release ? false, git_version ? null, features ? null, }: -with import ./common.nix; - let log = v: builtins.trace v v; - pkgs = import pkgsSrc { - inherit system; - crossSystem = { - config = target; - isStatic = true; - }; - overlays = [ cargo2nixOverlay ]; - }; + pkgs = + if target != null then + import pkgsSrc { + inherit system; + crossSystem = { + config = target; + isStatic = true; + }; + overlays = [ cargo2nixOverlay ]; + } + else + import pkgsSrc { + inherit system; + overlays = [ cargo2nixOverlay ]; + }; /* Cargo2nix is built for rustOverlay which installs Rust from Mozilla releases. @@ -34,7 +41,7 @@ let NixOS ships them in separate ones. We reunite them with symlinkJoin. */ toolchainOptions = - if target == "x86_64-unknown-linux-musl" || target == "aarch64-unknown-linux-musl" then { + if target == null || target == "x86_64-unknown-linux-musl" || target == "aarch64-unknown-linux-musl" then { rustVersion = "1.63.0"; extraRustComponents = [ "clippy" ]; } else { @@ -1,5 +1,5 @@ { - system ? builtins.currentSystem, + system ? builtins.currentSystem, }: with import ./nix/common.nix; @@ -71,13 +71,25 @@ function refresh_cache { for attr in clippy.amd64 test.amd64 pkgs.{amd64,i386,arm,arm64}.{debug,release}; do echo "Updating cache for ''${attr}" derivation=$(nix-instantiate --attr ''${attr}) - nix copy \ + nix copy -j8 \ --to 's3://nix?endpoint=garage.deuxfleurs.fr®ion=garage&secret-key=/tmp/nix-signing-key.sec' \ $(nix-store -qR ''${derivation%\!bin}) done rm /tmp/nix-signing-key.sec } +function refresh_flake_cache { + pass show deuxfleurs/nix_priv_key > /tmp/nix-signing-key.sec + for attr in packages.x86_64-linux.default; do + echo "Updating cache for ''${attr}" + derivation=$(nix path-info --derivation ".#''${attr}") + nix copy -j8 \ + --to 's3://nix?endpoint=garage.deuxfleurs.fr®ion=garage&secret-key=/tmp/nix-signing-key.sec' \ + $(nix-store -qR ''${derivation}) + done + rm /tmp/nix-signing-key.sec +} + function to_s3 { aws \ --endpoint-url https://garage.deuxfleurs.fr \ |