nixnix-flake

How should I write a flake.nix in order to use nix develop instead of nix develop github:project#shell


NB: add --extra-experimental-features nix-command --extra-experimental-features flakes if you've allowed experimental feature in nix

This repository proposes to load a shell this way:

nix develop github:informalsystems/cosmos.nix#cosmos-shell

It seems to work.

In order to see if I've really understood how nix flake works (I haven't) I am trying to write a flake.nix so that I only have to write

nix develop

There is a field devShells (not devShell) in output in flake.nix in this repo. This is a collection of shells defined in configuration.nix.

My flake.nix:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";  #not useful for this question
    cosmos_inform_system.url = github:informalsystems/cosmos.nix;
    flake-utils.url = github:numtide/flake-utils;
  };

  outputs = { self, nixpkgs, cosmos_inform_system, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        shells = cosmos_inform_system.devShells;
      in {
        devShell.default = shells.cosmos-shell;
      });
}
warning: flake output attribute 'devShell' is deprecated; use 'devShells.<system>.default' instead
error: attribute 'cosmos-shell' missing

There is cosmos-shell in configuration.nix this a field devShells. Therefore I don't understand the error

In order to remove the warning, I replace this line

devShell = shells.cosmos-shell;

with this line:

devShells.${system}.default = shells.cosmos-shell;

error: flake attribute 'devShell.aarch64-linux' is not a derivation

I still have the warning.


Solution

  • nix flake check 
    

    works with that

    {
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
        cosmos_inform_system.url = github:informalsystems/cosmos.nix;
        flake-utils.url = github:numtide/flake-utils;
      };
    
      outputs = { self, nixpkgs, cosmos_inform_system, flake-utils, ... }:
        flake-utils.lib.eachDefaultSystem (system:
          let
            shells = cosmos_inform_system.devShells;
          in {
            devShells.default = shells.${system}.cosmos-shell;
          }
        );
    }
    

    but nix develop

    error: hash mismatch in fixed-output derivation '/nix/store/yz9kjwjhszzpp7g4wnbxj43zwga1zzsy-ica-go-modules.drv': specified: sha256-ykGo5TQ+MiFoeQoglflQL3x3VN2CQuyZCIiweP/c9lM= got: sha256-D31e+G/7KAmF3Gkk4IOmU2g/eLlqkrkpwJa7CEjdaAk=

    [1/158 built (1 failed)] building ica-go-modules (installPhase): installing

    Nevertheless I have exactly the same problem with nix develop github:informalsystems/cosmos.nix#cosmos-shell

    I still think my flake file is the same as nix develop github:informalsystems/cosmos.nix#cosmos-shell