A fork of attic a self-hostable Nix Binary Cache server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #174 from zhaofengli/devshell-nix-consistency

flake: Follow package Nix version in dev shell

authored by

Zhaofeng Li and committed by
GitHub
416687e5 54bbd7d5

+72 -65
+64 -61
attic/build.rs
··· 2 2 //! 3 3 //! We link against libnixstore to perform actions on the Nix Store. 4 4 5 - use cc::Build; 6 - use version_compare::Version; 7 - 8 - struct NixDependency { 9 - version: String, 5 + fn main() { 6 + #[cfg(feature = "nix_store")] 7 + nix_store::build_bridge(); 10 8 } 11 9 12 - impl NixDependency { 13 - fn detect() -> Self { 14 - let library = pkg_config::Config::new() 15 - .cargo_metadata(false) 16 - .atleast_version("2.4") 17 - .probe("nix-main") 18 - .expect("Failed to find nix-main >=2.4 through pkg-config"); 10 + #[cfg(feature = "nix_store")] 11 + mod nix_store { 12 + use cc::Build; 13 + use version_compare::Version; 19 14 20 - Self { 21 - version: library.version, 15 + struct NixDependency { 16 + version: String, 17 + } 18 + 19 + impl NixDependency { 20 + fn detect() -> Self { 21 + let library = pkg_config::Config::new() 22 + .cargo_metadata(false) 23 + .atleast_version("2.4") 24 + .probe("nix-main") 25 + .expect("Failed to find nix-main >=2.4 through pkg-config"); 26 + 27 + Self { 28 + version: library.version, 29 + } 22 30 } 23 - } 24 31 25 - fn apply_version_flags(&self, build: &mut Build) { 26 - let version = Version::from(&self.version).unwrap(); 32 + fn apply_version_flags(&self, build: &mut Build) { 33 + let version = Version::from(&self.version).unwrap(); 27 34 28 - if version >= Version::from("2.20").unwrap() { 29 - build.flag("-DATTIC_NIX_2_20"); 35 + if version >= Version::from("2.20").unwrap() { 36 + build.flag("-DATTIC_NIX_2_20"); 37 + } 30 38 } 31 - } 32 39 33 - fn emit_cargo_metadata(&self) { 34 - pkg_config::Config::new() 35 - .atleast_version("2.4") 36 - .probe("nix-store") 37 - .unwrap(); 40 + fn emit_cargo_metadata(&self) { 41 + pkg_config::Config::new() 42 + .atleast_version("2.4") 43 + .probe("nix-store") 44 + .unwrap(); 38 45 39 - pkg_config::Config::new() 40 - .atleast_version("2.4") 41 - .probe("nix-main") 42 - .unwrap(); 46 + pkg_config::Config::new() 47 + .atleast_version("2.4") 48 + .probe("nix-main") 49 + .unwrap(); 50 + } 43 51 } 44 - } 45 52 46 - fn main() { 47 - #[cfg(feature = "nix_store")] 48 - build_bridge(); 49 - } 53 + pub fn build_bridge() { 54 + let nix_dep = NixDependency::detect(); 50 55 51 - #[cfg(feature = "nix_store")] 52 - fn build_bridge() { 53 - let nix_dep = NixDependency::detect(); 56 + // Temporary workaround for issue in <https://github.com/NixOS/nix/pull/8484> 57 + let hacky_include = { 58 + let dir = 59 + tempfile::tempdir().expect("Failed to create temporary directory for workaround"); 60 + std::fs::write(dir.path().join("uds-remote-store.md"), "\"\"").unwrap(); 61 + dir 62 + }; 54 63 55 - // Temporary workaround for issue in <https://github.com/NixOS/nix/pull/8484> 56 - let hacky_include = { 57 - let dir = tempfile::tempdir().expect("Failed to create temporary directory for workaround"); 58 - std::fs::write(dir.path().join("uds-remote-store.md"), "\"\"").unwrap(); 59 - dir 60 - }; 61 - 62 - let mut build = cxx_build::bridge("src/nix_store/bindings/mod.rs"); 63 - build 64 - .file("src/nix_store/bindings/nix.cpp") 65 - .flag("-std=c++2a") 66 - .flag("-O2") 67 - .flag("-include") 68 - .flag("nix/config.h") 69 - .flag("-idirafter") 70 - .flag(hacky_include.path().to_str().unwrap()) 71 - // In Nix 2.19+, nix/args/root.hh depends on being able to #include "args.hh" (which is in its parent directory), for some reason 72 - .flag("-I") 73 - .flag(concat!(env!("NIX_INCLUDE_PATH"), "/nix")); 64 + let mut build = cxx_build::bridge("src/nix_store/bindings/mod.rs"); 65 + build 66 + .file("src/nix_store/bindings/nix.cpp") 67 + .flag("-std=c++2a") 68 + .flag("-O2") 69 + .flag("-include") 70 + .flag("nix/config.h") 71 + .flag("-idirafter") 72 + .flag(hacky_include.path().to_str().unwrap()) 73 + // In Nix 2.19+, nix/args/root.hh depends on being able to #include "args.hh" (which is in its parent directory), for some reason 74 + .flag("-I") 75 + .flag(concat!(env!("NIX_INCLUDE_PATH"), "/nix")); 74 76 75 - nix_dep.apply_version_flags(&mut build); 77 + nix_dep.apply_version_flags(&mut build); 76 78 77 - build.compile("nixbinding"); 79 + build.compile("nixbinding"); 78 80 79 - println!("cargo:rerun-if-changed=src/nix_store/bindings"); 81 + println!("cargo:rerun-if-changed=src/nix_store/bindings"); 80 82 81 - // the -l flags must be after -lnixbinding 82 - nix_dep.emit_cargo_metadata(); 83 + // the -l flags must be after -lnixbinding 84 + nix_dep.emit_cargo_metadata(); 85 + } 83 86 }
+4
crane.nix
··· 109 109 maintainers = with maintainers; [ zhaofengli ]; 110 110 platforms = platforms.linux ++ platforms.darwin; 111 111 }; 112 + 113 + passthru = { 114 + inherit nix; 115 + }; 112 116 } // args // extraArgs); 113 117 114 118 attic = mkAttic {
+3 -3
flake.lock
··· 58 58 }, 59 59 "nixpkgs": { 60 60 "locked": { 61 - "lastModified": 1724999960, 62 - "narHash": "sha256-LB3jqSGW5u1ZcUcX6vO/qBOq5oXHlmOCxsTXGMEitp4=", 61 + "lastModified": 1726042813, 62 + "narHash": "sha256-LnNKCCxnwgF+575y0pxUdlGZBO/ru1CtGHIqQVfvjlA=", 63 63 "owner": "NixOS", 64 64 "repo": "nixpkgs", 65 - "rev": "b96f849e725333eb2b1c7f1cb84ff102062468ba", 65 + "rev": "159be5db480d1df880a0135ca0bfed84c2f88353", 66 66 "type": "github" 67 67 }, 68 68 "original": {
+1 -1
flake/devshells.nix
··· 97 97 NIX_PATH = "nixpkgs=${pkgs.path}"; 98 98 99 99 # See comment in `attic/build.rs` 100 - NIX_INCLUDE_PATH = "${lib.getDev pkgs.nixVersions.nix_2_24}/include"; 100 + NIX_INCLUDE_PATH = "${lib.getDev self'.packages.attic.passthru.nix}/include"; 101 101 102 102 # Used by `just with-nix` to build/test with alternative Nix versions. 103 103 NIX_VERSIONS = config.attic.nix-versions.manifestFile;