Skip to content

Instantly share code, notes, and snippets.

@ldesgoui
Last active June 11, 2021 15:03
Show Gist options
  • Save ldesgoui/8e5e216c4c2261455f5f03e0d35c9ec1 to your computer and use it in GitHub Desktop.
Save ldesgoui/8e5e216c4c2261455f5f03e0d35c9ec1 to your computer and use it in GitHub Desktop.
Checking a flake in recursive Nix
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1614513358,
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1622966049,
"narHash": "sha256-6g+28v94ISkVk9TBSsITVOnB2slK8plieWPIF2jo/l0=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "fbfb79400a08bf754e32b4d4fc3f7d8f8055cf94",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1623378256,
"narHash": "sha256-nlSwmn7ywh02EOkr+pnrq3yiD/Wq1GjAirEuHQLqbss=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "45fbdefb8cdd5f4e8e28e27ae1f2a90241e66529",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
{
description = "I'M FRED POO";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs @ { self, nixpkgs, ... }:
let
supportedSystems = [
"x86_64-linux"
];
overlays = [
inputs.rust-overlay.overlay
];
perSystem = nixpkgs.lib.genAttrs supportedSystems;
pkgsPerSystem = f: perSystem (system: f (import nixpkgs { inherit system overlays; }));
appsPerSystem = names: perSystem (system: nixpkgs.lib.genAttrs names (name: {
type = "app";
program = "${self.packages."${system}"."${name}"}/bin/${name}";
}));
in
{
#$ nix run nixpkgs.nixUnstable -c nix develop
devShell = pkgsPerSystem (pkgs: pkgs.mkShell {
buildInputs = [
pkgs.rust-bin.stable.latest.default
];
});
checks = pkgsPerSystem (pkgs: {
hello = pkgs.hello.overrideAttrs (_: { name = "hello-rebuild"; });
});
packages = pkgsPerSystem (pkgs: {
fredpoo = pkgs.runCommand "fredpoo"
{
requiredSystemFeatures = [ "recursive-nix" ];
buildInputs = [ pkgs.nixUnstable ];
NIX_PATH = "nixpkgs=${nixpkgs}";
NIX_CONFIG = "experimental-features = nix-command flakes";
flake = self;
# Inject the sources of transitive inputs in the context
transitive =
let
inherit (builtins) substring;
inherit (nixpkgs.lib) attrValues concatMapStrings;
f = inputs:
concatMapStrings
(input: substring 0 0 input.outPath + f input.inputs)
(attrValues inputs);
in
f self.inputs;
}
''
# Shows the list of sources that were in context (supposedly)
nix --offline path-info --all | grep 'source$'
nix --show-trace --offline flake metadata $flake
nix --show-trace --offline flake check $flake
# touch $out
'';
build-fredpoo = pkgs.writeScriptBin "build-fredpoo" ''
${pkgs.nixUnstable}/bin/nix \
--experimental-features 'nix-command flakes recursive-nix' \
build ${self}#fredpoo
${pkgs.nixUnstable}/bin/nix log ${self}#fredpoo
'';
});
apps = appsPerSystem [ "build-fredpoo" ];
defaultApp = perSystem (system: self.apps."${system}".build-fredpoo);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment