subflakes: make first class citizens

Subflakes should provide their wares as outputs, so wire up the pkgs
flake to reflect that.

Due to the unstable nature of flakes, updating the root flake doesn't
currently update the subflake lock file. Therefore, add additional
logic to flk update script in order to do this behind the scenes.

Nix is now pulled in from the "nix" registry flake in order for users
to take advantage of improvements to the UI since its last update in
nixpkgs.
This commit is contained in:
Timothy DeHerrera 2021-03-14 21:27:58 -06:00
parent d7f15a664d
commit d51cd34fb7
No known key found for this signature in database
GPG key ID: 8985725DB5B0C122
12 changed files with 135 additions and 63 deletions

View file

@ -1,16 +1,22 @@
# update
The `update` subcommand is a simple alias for:
```sh
nix flake update --recreate-lock-file --commit-lock-file
nix flake update
```
As it sounds, this will update your lock file, and commit it.
As it sounds, this will update your lock file.
## Updating Package Sources
If you pass an input name then it will only update that input.
If you pass directory name then it will update that input if the directory
contains a flake.nix, with an optional arguement to update only a specific
input in the subflake.
For example, you can update any
[package sources](../../pkgs#automatic-source-updates) you may have declared
in _pkgs/flake.nix_:
```sh
flk update srcs
flk update pkgs
```
or just its _nixpkgs_:
```sh
flk update pkgs nixpkgs
```

2
extern/default.nix vendored
View file

@ -9,11 +9,13 @@ in
];
overlays = [
nix.overlay
nur.overlay
devshell.overlay
(final: prev: {
deploy-rs = deploy.packages.${prev.system}.deploy-rs;
})
pkgs.overlay
];
# passed to all nixos modules

View file

@ -152,6 +152,25 @@
"type": "github"
}
},
"nix": {
"inputs": {
"nixpkgs": [
"nixos"
]
},
"locked": {
"lastModified": 1615476733,
"narHash": "sha256-iae4JMAl2KAaPhUGLMf4/DEejWjs5fWfEU1ccVF8s6Q=",
"owner": "NixOS",
"repo": "nix",
"rev": "8127094f767b6caae145bc395a504ca62f30af3e",
"type": "github"
},
"original": {
"id": "nix",
"type": "indirect"
}
},
"nixos": {
"locked": {
"lastModified": 1614531331,
@ -210,6 +229,22 @@
"type": "indirect"
}
},
"pkgs": {
"inputs": {
"nixpkgs": [
"nixos"
]
},
"locked": {
"narHash": "sha256-sBVaeGxxs7sk7PodW1mqJbF0CqUqUar0GUdd+OPnZ8o=",
"path": "./pkgs",
"type": "path"
},
"original": {
"path": "./pkgs",
"type": "path"
}
},
"pre-commit-hooks-nix": {
"flake": false,
"locked": {
@ -235,25 +270,15 @@
"flake-compat": "flake-compat",
"home": "home",
"naersk": "naersk",
"nix": "nix",
"nixos": "nixos",
"nixos-hardware": "nixos-hardware",
"nur": "nur",
"override": "override",
"srcs": "srcs",
"pkgs": "pkgs",
"utils": "utils"
}
},
"srcs": {
"locked": {
"narHash": "sha256-Ot96/oKT5+A5kdqkfYyT45cfEiqhI5UyPdEfEZjbXaA=",
"path": "./pkgs",
"type": "path"
},
"original": {
"path": "./pkgs",
"type": "path"
}
},
"utils": {
"locked": {
"lastModified": 1608663846,

View file

@ -22,12 +22,14 @@
home.inputs.nixpkgs.follows = "nixos";
naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "override";
nix.inputs.nixpkgs.follows = "nixos";
nixos-hardware.url = "github:nixos/nixos-hardware";
utils.url = "github:numtide/flake-utils/flatten-tree-system";
srcs.url = "path:./pkgs";
pkgs.url = "path:./pkgs";
pkgs.inputs.nixpkgs.follows = "nixos";
};
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }:
outputs = inputs@{ deploy, nixos, nur, nix, self, utils, ... }:
let
inherit (self) lib;
inherit (lib) os;

View file

@ -14,42 +14,6 @@ in
(overridesOverlay overridePkgs)
self.overlay
(final: prev: {
srcs =
let
mkVersion = name: input:
let
inputs = (builtins.fromJSON
(builtins.readFile ../../flake.lock)).nodes;
ref =
if lib.hasAttrByPath [ name "original" "ref" ] inputs
then inputs.${name}.original.ref
else "";
version =
let version' = builtins.match
"[[:alpha:]]*[-._]?([0-9]+(\.[0-9]+)*)+"
ref;
in
if lib.isList version'
then lib.head version'
else if input ? lastModifiedDate && input ? shortRev
then "${lib.substring 0 8 input.lastModifiedDate}_${input.shortRev}"
else null;
in
version;
in
lib.mapAttrs
(name: input:
let
version = mkVersion name input;
in
input // lib.optionalAttrs (! isNull version)
{
inherit version;
}
)
self.inputs.srcs.inputs;
lib = prev.lib.extend (lfinal: lprev: {
inherit dev;
inherit (lib) nixosSystem;

View file

@ -1,5 +1,5 @@
final: prev: {
nixFlakes = prev.nixFlakes.overrideAttrs
nixFlakes = final.nix.overrideAttrs
(self:
let
oldPatches = self.patches or [ ];

View file

@ -9,12 +9,12 @@
# packages pulled from override
packages = pkgs: final: prev: {
inherit (pkgs)
cachix
dhall
discord
element-desktop
manix
nixpkgs-fmt
nixFlakes
qutebrowser
signal-desktop
starship;

25
pkgs/flake.lock Normal file
View file

@ -0,0 +1,25 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1615769536,
"narHash": "sha256-oah5pb8kXyFa6ZcccvfREuY9VXHkUTNaoClXW7H1XUw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "63a9f162355ec84c423690869a97848d73409fb8",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View file

@ -1,7 +1,52 @@
{
description = "Package sources";
description = "Package Sources";
inputs = { };
outputs = { ... }: { };
outputs = { self, nixpkgs, ... }: {
overlay = final: prev: {
inherit (self) srcs;
};
srcs =
let
inherit (nixpkgs) lib;
mkVersion = name: input:
let
inputs = (builtins.fromJSON
(builtins.readFile ./flake.lock)).nodes;
ref =
if lib.hasAttrByPath [ name "original" "ref" ] inputs
then inputs.${name}.original.ref
else "";
version =
let version' = builtins.match
"[[:alpha:]]*[-._]?([0-9]+(\.[0-9]+)*)+"
ref;
in
if lib.isList version'
then lib.head version'
else if input ? lastModifiedDate && input ? shortRev
then "${lib.substring 0 8 input.lastModifiedDate}_${input.shortRev}"
else null;
in
version;
in
lib.mapAttrs
(pname: input:
let
version = mkVersion pname input;
in
input // { inherit pname; }
// lib.optionalAttrs (! isNull version)
{
inherit version;
}
)
(lib.filterAttrs (n: _: n != "nixpkgs")
self.inputs);
};
}

View file

@ -22,6 +22,7 @@ pkgs.devshell.mkShell
nixos-install
nixos-generate-config
nixos-enter
pkgs.nixFlakes
];
git.hooks = {

View file

@ -25,8 +25,5 @@ category = "documentation"
package = "mdbook"
category = "documentation"
[[commands]]
package = "nixFlakes"
[git.hooks]
enable = true

View file

@ -50,9 +50,14 @@ case "$1" in
"update")
if [[ -n "$2" ]]; then
nix flake update --update-input "$2" --commit-lock-file "$DEVSHELL_ROOT"
if [[ -n "$3" ]]; then
(cd $2; nix flake list-inputs --update-input "$3")
else
nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT"
(cd $2; nix flake update)
fi
nix flake list-inputs --update-input "$2" "$DEVSHELL_ROOT"
else
nix flake update "$DEVSHELL_ROOT"
fi
;;