Hi there, I’m a beginner to Nix (think it’s super cool so far) - just having an issue with creating a flake to develop Golang with. I’ve been trying to use an old version of the golang lint package: Nix Package Versions
My flake.nix is:
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
pkgs = import (builtins.fetchGit {
# Descriptive name to make the store path easier to identify
name = "my-old-revision";
url = "https://github.com/NixOS/nixpkgs/";
ref = "refs/heads/nixpkgs-unstable";
rev = "ff8b619cfecb98bb94ae49ca7ceca937923a75fa";
}) {};
myPkg = pkgs.golangci-lint;
in
mkShell {
nativeBuildInputs = [
go_1_18
gopls
tmux
gofumpt
myPkg
gosec
delve
go-tools
gotests
gomodifytags
];
}
The error I get is:
error: attribute 'currentSystem' missing
at /nix/store/lgbjq8aqhz9l0n607klg4b0l4nh19fba-my-old-revision/pkgs/top-level/impure.nix:17:43:
16| # (build, in GNU Autotools parlance) platform.
17| localSystem ? { system = args.system or builtins.currentSystem; }
| ^
18|
(use '--show-trace' to show detailed location information)
I assume the error is something to do with impurities with bringing in the system, but I’m not sure how to declare it as input. Many thanks in advance for the help!
You’re basically pinning nixpkgs twice, once explicitly in shell.nix when you assign to pkgs and once implicitly by using flakes.
I think you can use nix flake update with some flags to set nixpkgs to the specific revision, or if you only want the pinned nixpkgs for that package, you can additionally pass system to your shell.nix and pass it through to where you import nixpkgs from the pinned version.
(I’m on my phone so I can’t really post code, hope that helps otherwise I’ll elaborate tomorrow)
Yes, builtins.currentSystem does not intentionally work in flakes. You need to pass system attribute explicitly as an attribute to the imported Nixpkgs. You can add system as a shell.nix attribute and pass it in flake.nix.
The builtins.currentSystem in your flake.nix does not cause an issue because Nix is lazy and outputs.system.${…} attribute will not be evaluated when building the shell.
Hey thanks for your answer. How do I implement this?
I’ve tried adding the line: system = builtins.currentSystem;
To the let statement in shell.nix and inside the mkShell curly braces but neither seem to work